mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-05 17:06:18 +01:00
GHashTable: Small optimization of remove-all
Don't enter the loop if we are not going to notify anyway. Pointed out in bug 646013.
This commit is contained in:
parent
fc7403b675
commit
d3b80c49ea
12
glib/ghash.c
12
glib/ghash.c
@ -479,22 +479,28 @@ g_hash_table_remove_all_nodes (GHashTable *hash_table,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (notify &&
|
||||||
|
(hash_table->key_destroy_func != NULL ||
|
||||||
|
hash_table->value_destroy_func != NULL))
|
||||||
|
{
|
||||||
for (i = 0; i < hash_table->size; i++)
|
for (i = 0; i < hash_table->size; i++)
|
||||||
{
|
{
|
||||||
GHashNode *node = &hash_table->nodes [i];
|
GHashNode *node = &hash_table->nodes [i];
|
||||||
|
|
||||||
if (node->key_hash > 1)
|
if (node->key_hash > 1)
|
||||||
{
|
{
|
||||||
if (notify && hash_table->key_destroy_func)
|
if (hash_table->key_destroy_func != NULL)
|
||||||
hash_table->key_destroy_func (node->key);
|
hash_table->key_destroy_func (node->key);
|
||||||
|
|
||||||
if (notify && hash_table->value_destroy_func)
|
if (hash_table->value_destroy_func != NULL)
|
||||||
hash_table->value_destroy_func (node->value);
|
hash_table->value_destroy_func (node->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* We need to set node->key_hash = 0 for all nodes - might as well be GC
|
/* We need to set node->key_hash = 0 for all nodes - might as well be GC
|
||||||
* friendly and clear everything */
|
* friendly and clear everything
|
||||||
|
*/
|
||||||
memset (hash_table->nodes, 0, hash_table->size * sizeof (GHashNode));
|
memset (hash_table->nodes, 0, hash_table->size * sizeof (GHashNode));
|
||||||
|
|
||||||
hash_table->nnodes = 0;
|
hash_table->nnodes = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user