[glib/wip/th/fix-small-array-hash-valgrind] ghash: remember not to use small-array optimization during g_hash_table_remove_all_nodes()



commit 5e735bf8e466e65e752f28e863fb51f028dcccb4
Author: Thomas Haller <thaller redhat com>
Date:   Wed May 15 15:36:46 2019 +0200

    ghash: remember not to use small-array optimization during g_hash_table_remove_all_nodes()
    
    g_hash_table_remove_all_nodes() gets called during g_hash_table_remove_all()
    (among others).
    
    It clears the allocated buffers and allocates new ones. Thereby it also
    resets "hash_table->have_big_{keys,values}".
    
    Note that when we are running under valgrind, we don't want to use the
    small-array optimization. Hence, we must not unconditionally reset
    "hash_table->have_big_{keys,values}" but depending on whether valgrind
    is in place.
    
    Instead of repeating the detection (which is dupliate code), remember
    the original decision in "hash_table->use_small_arrays".

 glib/ghash.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/glib/ghash.c b/glib/ghash.c
index 14cbaf80b..68dcb9bd4 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -255,6 +255,7 @@ struct _GHashTable
   gint             nnodes;
   gint             noccupied;  /* nnodes + tombstones */
 
+  guint            use_small_arrays : 1;
   guint            have_big_keys : 1;
   guint            have_big_values : 1;
 
@@ -623,7 +624,7 @@ g_hash_table_remove_all_nodes (GHashTable *hash_table,
   g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT);
   if (!destruction)
     {
-      hash_table->keys   = g_hash_table_realloc_key_or_value_array (NULL, hash_table->size, FALSE);
+      hash_table->keys   = g_hash_table_realloc_key_or_value_array (NULL, hash_table->size, 
!hash_table->use_small_arrays);
       hash_table->values = hash_table->keys;
       hash_table->hashes = g_new0 (guint, hash_table->size);
     }
@@ -654,8 +655,8 @@ g_hash_table_remove_all_nodes (GHashTable *hash_table,
         }
     }
 
-  hash_table->have_big_keys = FALSE;
-  hash_table->have_big_values = FALSE;
+  hash_table->have_big_keys = !hash_table->use_small_arrays;
+  hash_table->have_big_values = !hash_table->use_small_arrays;
 
   /* Destroy old storage space. */
   if (old_keys != old_values)
@@ -1046,6 +1047,7 @@ g_hash_table_new_full (GHashFunc      hash_func,
 #endif
   hash_table->key_destroy_func   = key_destroy_func;
   hash_table->value_destroy_func = value_destroy_func;
+  hash_table->use_small_arrays   = small;
   hash_table->have_big_keys      = !small;
   hash_table->have_big_values    = !small;
   hash_table->keys               = g_hash_table_realloc_key_or_value_array (NULL, hash_table->size, 
hash_table->have_big_keys);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]