ghash: Allow tweaking hash table shift by environment variable

The shift controls the capacity of the hash table before it needs to
be resized.

This commit makes the shift configurable through the

G_HASH_TABLE_MIN_SHIFT

environment variable.
This commit is contained in:
Ray Strode 2021-05-10 16:02:31 -04:00
parent a97d9c6389
commit a4b72a282c

View File

@ -206,7 +206,7 @@
* release of GLib. It does nothing.
*/
#define HASH_TABLE_MIN_SHIFT 3 /* 1 << 3 == 8 buckets */
static int HASH_TABLE_MIN_SHIFT = 3;
#define UNUSED_HASH_VALUE 0
#define TOMBSTONE_HASH_VALUE 1
@ -714,7 +714,7 @@ g_hash_table_new_full (GHashFunc hash_func,
GDestroyNotify value_destroy_func)
{
GHashTable *hash_table;
HASH_TABLE_MIN_SHIFT = atoi(getenv ("G_HASH_TABLE_MIN_SHIFT")? : "3");
hash_table = g_slice_new (GHashTable);
g_hash_table_set_shift (hash_table, HASH_TABLE_MIN_SHIFT);
hash_table->nnodes = 0;