[glib/wip/th/fix-small-array-hash-valgrind: 1/2] ghash: fix disabling small-array optimization under valgrind
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/th/fix-small-array-hash-valgrind: 1/2] ghash: fix disabling small-array optimization under valgrind
- Date: Wed, 15 May 2019 14:41:34 +0000 (UTC)
commit ae689ec229d50fbf0d3618f19f73f2762d8e528e
Author: Thomas Haller <thaller redhat com>
Date: Wed May 15 15:36:46 2019 +0200
ghash: fix disabling small-array optimization under valgrind
We must determine whether small-arrays are disabled early.
Especially before:
hash_table->keys = g_hash_table_realloc_key_or_value_array (NULL, hash_table->size, FALSE);
While at it, during g_hash_table_remove_all_nodes() we also reset the
@have_big_keys and @have_big_values fields. Don't reset them to FALSE,
when we run under valgrind.
Fixes: 436ca1f37685bdd36810da359d13a251cd456754
glib/ghash.c | 45 ++++++++++++++++++++++-----------------------
1 file changed, 22 insertions(+), 23 deletions(-)
---
diff --git a/glib/ghash.c b/glib/ghash.c
index 4204f51a4..dbb09c373 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)
@@ -1017,9 +1018,25 @@ g_hash_table_new_full (GHashFunc hash_func,
GDestroyNotify value_destroy_func)
{
GHashTable *hash_table;
- gboolean small;
+ gboolean small = FALSE;
+
+ /* We want to use small arrays only if:
+ * - we are running on a system where that makes sense (64 bit); and
+ * - we are not running under valgrind.
+ */
+#ifdef USE_SMALL_ARRAYS
+ small = TRUE;
+# ifdef ENABLE_VALGRIND
+ if (RUNNING_ON_VALGRIND)
+ small = FALSE;
+# endif
+#endif
hash_table = g_slice_new (GHashTable);
+
+ hash_table->use_small_arrays = small;
+ hash_table->have_big_keys = !small;
+ hash_table->have_big_values = !small;
g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT);
g_atomic_ref_count_init (&hash_table->ref_count);
hash_table->nnodes = 0;
@@ -1031,28 +1048,10 @@ 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->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, !small);
hash_table->values = hash_table->keys;
hash_table->hashes = g_new0 (guint, hash_table->size);
- /* We want to use small arrays only if:
- * - we are running on a system where that makes sense (64 bit); and
- * - we are not running under valgrind.
- */
- small = FALSE;
-
-#ifdef USE_SMALL_ARRAYS
- small = TRUE;
-
-# ifdef ENABLE_VALGRIND
- if (RUNNING_ON_VALGRIND)
- small = FALSE;
-# endif
-#endif
-
- hash_table->have_big_keys = !small;
- hash_table->have_big_values = !small;
-
return hash_table;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]