mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
ghash: Be less eager to opportunistically grow the table on cleanup
When g_hash_table_resize() gets called, we clear out tombstones and grow the table at the same time if needed. However, the threshold was set too low, so we'd grow if the load was greater than .5 after subtracting tombstones. Increase this threshold to ~.75.
This commit is contained in:
parent
7eaf018b29
commit
194eef5f17
13
glib/ghash.c
13
glib/ghash.c
@ -814,7 +814,18 @@ g_hash_table_resize (GHashTable *hash_table)
|
||||
old_size = hash_table->size;
|
||||
is_a_set = hash_table->keys == hash_table->values;
|
||||
|
||||
g_hash_table_set_shift_from_size (hash_table, hash_table->nnodes * 2);
|
||||
/* The outer checks in g_hash_table_maybe_resize() will only consider
|
||||
* cleanup/resize when the load factor goes below .25 (1/4, ignoring
|
||||
* tombstones) or above .9375 (15/16, including tombstones).
|
||||
*
|
||||
* Once this happens, tombstones will always be cleaned out. If our
|
||||
* load sans tombstones is greater than .75 (1/1.333, see below), we'll
|
||||
* take this opportunity to grow the table too.
|
||||
*
|
||||
* Immediately after growing, the load factor will be in the range
|
||||
* .375 .. .469. After shrinking, it will be exactly .5. */
|
||||
|
||||
g_hash_table_set_shift_from_size (hash_table, hash_table->nnodes * 1.333);
|
||||
|
||||
if (hash_table->size > old_size)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user