[glib] GHashTable: Small optimization of remove-all
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GHashTable: Small optimization of remove-all
- Date: Wed, 27 Apr 2011 04:04:44 +0000 (UTC)
commit d3b80c49ea257d02838099e05e315a2407e664b9
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Apr 27 00:03:59 2011 -0400
GHashTable: Small optimization of remove-all
Don't enter the loop if we are not going to notify anyway.
Pointed out in bug 646013.
glib/ghash.c | 24 +++++++++++++++---------
1 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/glib/ghash.c b/glib/ghash.c
index 4323068..d62db57 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -479,22 +479,28 @@ g_hash_table_remove_all_nodes (GHashTable *hash_table,
{
int i;
- for (i = 0; i < hash_table->size; i++)
+ if (notify &&
+ (hash_table->key_destroy_func != NULL ||
+ hash_table->value_destroy_func != NULL))
{
- GHashNode *node = &hash_table->nodes [i];
-
- if (node->key_hash > 1)
+ for (i = 0; i < hash_table->size; i++)
{
- if (notify && hash_table->key_destroy_func)
- hash_table->key_destroy_func (node->key);
+ GHashNode *node = &hash_table->nodes [i];
- if (notify && hash_table->value_destroy_func)
- hash_table->value_destroy_func (node->value);
+ if (node->key_hash > 1)
+ {
+ if (hash_table->key_destroy_func != NULL)
+ hash_table->key_destroy_func (node->key);
+
+ if (hash_table->value_destroy_func != NULL)
+ hash_table->value_destroy_func (node->value);
+ }
}
}
/* 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));
hash_table->nnodes = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]