Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bugs, smells and cosmetics of the day
[simgrid.git] / src / xbt / dict.cpp
index dbd2865..9d5dc32 100644 (file)
@@ -113,7 +113,8 @@ static void xbt_dict_rehash(xbt_dict_t dict)
 
   xbt_dictelm_t *currcell = (xbt_dictelm_t *) xbt_realloc((char *) dict->table, newsize * sizeof(xbt_dictelm_t));
   memset(&currcell[oldsize], 0, oldsize * sizeof(xbt_dictelm_t));       /* zero second half */
-  dict->table_size = --newsize;
+  newsize--;
+  dict->table_size = newsize;
   dict->table = currcell;
   XBT_DEBUG("REHASH (%d->%d)", oldsize, newsize);
 
@@ -163,6 +164,7 @@ void xbt_dict_set_ext(xbt_dict_t dict, const char *key, int key_len, void *data,
   xbt_dictelm_t current;
   xbt_dictelm_t previous = nullptr;
 
+  xbt_assert(!free_ctn, "Cannot set an individual free function in homogeneous dicts.");
   XBT_CDEBUG(xbt_dict, "ADD %.*s hash = %u, size = %d, & = %u", key_len, key, hash_code,
              dict->table_size, hash_code & dict->table_size);
   current = dict->table[hash_code & dict->table_size];
@@ -174,7 +176,7 @@ void xbt_dict_set_ext(xbt_dict_t dict, const char *key, int key_len, void *data,
 
   if (current == nullptr) {
     /* this key doesn't exist yet */
-    current = xbt_dictelm_new(dict, key, key_len, hash_code, data, free_ctn);
+    current = xbt_dictelm_new(key, key_len, hash_code, data);
     dict->count++;
     if (previous == nullptr) {
       dict->table[hash_code & dict->table_size] = current;
@@ -533,9 +535,6 @@ void xbt_dict_preinit()
   if (dict_elm_mallocator == nullptr)
     dict_elm_mallocator = xbt_mallocator_new(256, dict_elm_mallocator_new_f, dict_elm_mallocator_free_f,
       dict_elm_mallocator_reset_f);
-  if (dict_het_elm_mallocator == nullptr)
-    dict_het_elm_mallocator = xbt_mallocator_new(256, dict_het_elm_mallocator_new_f, dict_het_elm_mallocator_free_f,
-      dict_het_elm_mallocator_reset_f);
 }
 
 /**
@@ -547,8 +546,6 @@ void xbt_dict_postexit()
   if (dict_elm_mallocator != nullptr) {
     xbt_mallocator_free(dict_elm_mallocator);
     dict_elm_mallocator = nullptr;
-    xbt_mallocator_free(dict_het_elm_mallocator);
-    dict_het_elm_mallocator = nullptr;
   }
   if (all_sizes) {
     unsigned int count;
@@ -563,7 +560,10 @@ void xbt_dict_postexit()
         total_count += size;
       }
     }
-    printf("; %f elm per cell\n", avg / (double) total_count);
+    if (total_count > 0)
+      printf("; %f elm per cell\n", avg / (double)total_count);
+    else
+      printf("; 0 elm per cell\n");
   }
 }