convert G_HASH_TABLE_RESIZE() macro to inline function
authorRyan Lortie <desrt@desrt.ca>
Tue, 4 Dec 2007 03:46:13 +0000 (03:46 +0000)
committerRyan Lortie <ryanl@src.gnome.org>
Tue, 4 Dec 2007 03:46:13 +0000 (03:46 +0000)
2007-12-03  Ryan Lortie  <desrt@desrt.ca>

        * glib/ghash.c: convert G_HASH_TABLE_RESIZE() macro to inline function

svn path=/trunk/; revision=6033

ChangeLog
glib/ghash.c

index bf74fc0..355edaf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2007-12-03  Ryan Lortie  <desrt@desrt.ca>
 
+       * glib/ghash.c: convert G_HASH_TABLE_RESIZE() macro to inline function
+
+2007-12-03  Ryan Lortie  <desrt@desrt.ca>
+
        * glib/glib.symbols (glib_gettext): remove stray (duplicate) entry
        from file to fix the build
 
index 420d8c4..36e685f 100644 (file)
@@ -60,15 +60,6 @@ struct _GHashTable
   GDestroyNotify   value_destroy_func;
 };
 
-#define G_HASH_TABLE_RESIZE(hash_table)                                \
-   G_STMT_START {                                              \
-     if ((hash_table->size >= 3 * hash_table->nnodes &&                \
-         hash_table->size > HASH_TABLE_MIN_SIZE) ||            \
-        (3 * hash_table->size <= hash_table->nnodes &&         \
-         hash_table->size < HASH_TABLE_MAX_SIZE))              \
-          g_hash_table_resize (hash_table);                    \
-   } G_STMT_END
-
 static void            g_hash_table_resize       (GHashTable     *hash_table);
 static GHashNode**     g_hash_table_lookup_node  (GHashTable     *hash_table,
                                                    gconstpointer   key,
@@ -83,6 +74,16 @@ static guint g_hash_table_foreach_remove_or_steal (GHashTable     *hash_table,
 static void         g_hash_table_remove_all_nodes (GHashTable *hash_table,
                                                    gboolean        notify);
 
+static inline void
+g_hash_table_maybe_resize (GHashTable *hash_table)
+{
+  gint nnodes = hash_table->nnodes;
+  gint size = hash_table->size;
+
+  if ((size >= 3 * nnodes && size > HASH_TABLE_MIN_SIZE) ||
+      (3 * size <= nnodes && size < HASH_TABLE_MAX_SIZE))
+    g_hash_table_resize (hash_table);
+}
 
 /**
  * g_hash_table_new:
@@ -350,7 +351,7 @@ g_hash_table_insert_internal (GHashTable *hash_table,
     {
       *node = g_hash_node_new (key, value, key_hash);
       hash_table->nnodes++;
-      G_HASH_TABLE_RESIZE (hash_table);
+      g_hash_table_maybe_resize (hash_table);
     }
 }
 
@@ -448,7 +449,7 @@ g_hash_table_remove_internal (GHashTable    *hash_table,
     return FALSE;
 
   g_hash_table_remove_node (hash_table, &node_ptr, notify);
-  G_HASH_TABLE_RESIZE (hash_table);
+  g_hash_table_maybe_resize (hash_table);
 
   return TRUE;
 }
@@ -493,7 +494,7 @@ g_hash_table_remove_all (GHashTable *hash_table)
   g_return_if_fail (hash_table != NULL);
 
   g_hash_table_remove_all_nodes (hash_table, TRUE);
-  G_HASH_TABLE_RESIZE (hash_table);
+  g_hash_table_maybe_resize (hash_table);
 }
 
 /**
@@ -528,7 +529,7 @@ g_hash_table_steal_all (GHashTable *hash_table)
   g_return_if_fail (hash_table != NULL);
 
   g_hash_table_remove_all_nodes (hash_table, FALSE);
-  G_HASH_TABLE_RESIZE (hash_table);
+  g_hash_table_maybe_resize (hash_table);
 }
 
 /**
@@ -599,7 +600,7 @@ g_hash_table_foreach_remove_or_steal (GHashTable *hash_table,
       else
         node_ptr = &node->next;
 
-  G_HASH_TABLE_RESIZE (hash_table);
+  g_hash_table_maybe_resize (hash_table);
 
   return deleted;
 }