Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify a bit Keyval::attr_delete.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 25 May 2021 12:23:59 +0000 (14:23 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 25 May 2021 14:59:28 +0000 (16:59 +0200)
src/smpi/include/smpi_keyvals.hpp

index ab07655..46144a9 100644 (file)
@@ -94,18 +94,18 @@ template <typename T> int Keyval::attr_delete(int keyval){
   if (elem_it == T::keyvals_.end())
     return MPI_ERR_ARG;
 
+  auto attr = attributes().find(keyval);
+  if (attr == attributes().end())
+    return MPI_ERR_ARG;
+
   smpi_key_elem& elem = elem_it->second;
+  int flag            = 0;
+  int ret             = call_deleter<T>((T*)this, elem, keyval, attr->second, &flag);
+  if (ret != MPI_SUCCESS)
+    return ret;
+
   elem.refcount--;
-  void * value = nullptr;
-  int flag=0;
-  if(this->attr_get<T>(keyval, &value, &flag)==MPI_SUCCESS){
-    int ret = call_deleter<T>((T*)this, elem, keyval,value,&flag);
-    if(ret!=MPI_SUCCESS)
-        return ret;
-  }
-  if (attributes().empty())
-    return MPI_ERR_ARG;
-  attributes().erase(keyval);
+  attributes().erase(attr);
   return MPI_SUCCESS;
 }