mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 03:46:17 +01:00
ghash: Simplify g_hash_table_set_shift()
Even if we're using a prime modulo for the initial probe, our table is power-of-two-sized, meaning we can set the mask simply by subtracting one from the size.
This commit is contained in:
parent
0dee62973c
commit
171f698ead
14
glib/ghash.c
14
glib/ghash.c
@ -297,19 +297,15 @@ static const gint prime_mod [] =
|
||||
static void
|
||||
g_hash_table_set_shift (GHashTable *hash_table, gint shift)
|
||||
{
|
||||
gint i;
|
||||
guint mask = 0;
|
||||
|
||||
hash_table->size = 1 << shift;
|
||||
hash_table->mod = prime_mod [shift];
|
||||
|
||||
for (i = 0; i < shift; i++)
|
||||
{
|
||||
mask <<= 1;
|
||||
mask |= 1;
|
||||
}
|
||||
/* hash_table->size is always a power of two, so we can calculate the mask
|
||||
* by simply subtracting 1 from it. The leading assertion ensures that
|
||||
* we're really dealing with a power of two. */
|
||||
|
||||
hash_table->mask = mask;
|
||||
g_assert ((hash_table->size & (hash_table->size - 1)) == 0);
|
||||
hash_table->mask = hash_table->size - 1;
|
||||
}
|
||||
|
||||
static gint
|
||||
|
Loading…
Reference in New Issue
Block a user