Eliminate use of floating point when determining if the hash table needs
authorOwen Taylor <otaylor@redhat.com>
Mon, 20 Aug 2001 01:37:50 +0000 (01:37 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Mon, 20 Aug 2001 01:37:50 +0000 (01:37 +0000)
Sun Aug 19 21:32:39 2001  Owen Taylor  <otaylor@redhat.com>

* glib/ghash.c: Eliminate use of floating point when
determining if the hash table needs to be resized,
and also factor out the test from g_hash_table_resize()
to save function calls for the common case.
(#59124)

* glib/gmain.c (g_main_context_query): Document the
        return value.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/ghash.c
glib/gmain.c

index 7bf7a77..e9e250f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Sun Aug 19 21:32:39 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * glib/ghash.c: Eliminate use of floating point when 
+       determining if the hash table needs to be resized,
+       and also factor out the test from g_hash_table_resize()
+       to save function calls for the common case.
+       (#59124)
+
+       * glib/gmain.c (g_main_context_query): Document the
+       return value.
+
 2001-08-19  Darin Adler  <darin@bentspoon.com>
 
        * glib/gshell.c: (g_shell_quote): Added missing \ character.
index 7bf7a77..e9e250f 100644 (file)
@@ -1,3 +1,14 @@
+Sun Aug 19 21:32:39 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * glib/ghash.c: Eliminate use of floating point when 
+       determining if the hash table needs to be resized,
+       and also factor out the test from g_hash_table_resize()
+       to save function calls for the common case.
+       (#59124)
+
+       * glib/gmain.c (g_main_context_query): Document the
+       return value.
+
 2001-08-19  Darin Adler  <darin@bentspoon.com>
 
        * glib/gshell.c: (g_shell_quote): Added missing \ character.
index 7bf7a77..e9e250f 100644 (file)
@@ -1,3 +1,14 @@
+Sun Aug 19 21:32:39 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * glib/ghash.c: Eliminate use of floating point when 
+       determining if the hash table needs to be resized,
+       and also factor out the test from g_hash_table_resize()
+       to save function calls for the common case.
+       (#59124)
+
+       * glib/gmain.c (g_main_context_query): Document the
+       return value.
+
 2001-08-19  Darin Adler  <darin@bentspoon.com>
 
        * glib/gshell.c: (g_shell_quote): Added missing \ character.
index 7bf7a77..e9e250f 100644 (file)
@@ -1,3 +1,14 @@
+Sun Aug 19 21:32:39 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * glib/ghash.c: Eliminate use of floating point when 
+       determining if the hash table needs to be resized,
+       and also factor out the test from g_hash_table_resize()
+       to save function calls for the common case.
+       (#59124)
+
+       * glib/gmain.c (g_main_context_query): Document the
+       return value.
+
 2001-08-19  Darin Adler  <darin@bentspoon.com>
 
        * glib/gshell.c: (g_shell_quote): Added missing \ character.
index 7bf7a77..e9e250f 100644 (file)
@@ -1,3 +1,14 @@
+Sun Aug 19 21:32:39 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * glib/ghash.c: Eliminate use of floating point when 
+       determining if the hash table needs to be resized,
+       and also factor out the test from g_hash_table_resize()
+       to save function calls for the common case.
+       (#59124)
+
+       * glib/gmain.c (g_main_context_query): Document the
+       return value.
+
 2001-08-19  Darin Adler  <darin@bentspoon.com>
 
        * glib/gshell.c: (g_shell_quote): Added missing \ character.
index 7bf7a77..e9e250f 100644 (file)
@@ -1,3 +1,14 @@
+Sun Aug 19 21:32:39 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * glib/ghash.c: Eliminate use of floating point when 
+       determining if the hash table needs to be resized,
+       and also factor out the test from g_hash_table_resize()
+       to save function calls for the common case.
+       (#59124)
+
+       * glib/gmain.c (g_main_context_query): Document the
+       return value.
+
 2001-08-19  Darin Adler  <darin@bentspoon.com>
 
        * glib/gshell.c: (g_shell_quote): Added missing \ character.
index 7bf7a77..e9e250f 100644 (file)
@@ -1,3 +1,14 @@
+Sun Aug 19 21:32:39 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * glib/ghash.c: Eliminate use of floating point when 
+       determining if the hash table needs to be resized,
+       and also factor out the test from g_hash_table_resize()
+       to save function calls for the common case.
+       (#59124)
+
+       * glib/gmain.c (g_main_context_query): Document the
+       return value.
+
 2001-08-19  Darin Adler  <darin@bentspoon.com>
 
        * glib/gshell.c: (g_shell_quote): Added missing \ character.
index 7bf7a77..e9e250f 100644 (file)
@@ -1,3 +1,14 @@
+Sun Aug 19 21:32:39 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * glib/ghash.c: Eliminate use of floating point when 
+       determining if the hash table needs to be resized,
+       and also factor out the test from g_hash_table_resize()
+       to save function calls for the common case.
+       (#59124)
+
+       * glib/gmain.c (g_main_context_query): Document the
+       return value.
+
 2001-08-19  Darin Adler  <darin@bentspoon.com>
 
        * glib/gshell.c: (g_shell_quote): Added missing \ character.
index 62f4b95..28bc1c3 100644 (file)
@@ -59,6 +59,14 @@ 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,
@@ -304,7 +312,7 @@ g_hash_table_insert (GHashTable *hash_table,
     {
       *node = g_hash_node_new (key, value);
       hash_table->nnodes++;
-      g_hash_table_resize (hash_table);
+      G_HASH_TABLE_RESIZE (hash_table);
     }
 }
 
@@ -347,7 +355,7 @@ g_hash_table_replace (GHashTable *hash_table,
     {
       *node = g_hash_node_new (key, value);
       hash_table->nnodes++;
-      g_hash_table_resize (hash_table);
+      G_HASH_TABLE_RESIZE (hash_table);
     }
 }
 
@@ -383,7 +391,7 @@ g_hash_table_remove (GHashTable        *hash_table,
                           hash_table->value_destroy_func);
       hash_table->nnodes--;
   
-      g_hash_table_resize (hash_table);
+      G_HASH_TABLE_RESIZE (hash_table);
 
       return TRUE;
     }
@@ -417,7 +425,7 @@ g_hash_table_steal (GHashTable    *hash_table,
       g_hash_node_destroy (dest, NULL, NULL);
       hash_table->nnodes--;
   
-      g_hash_table_resize (hash_table);
+      G_HASH_TABLE_RESIZE (hash_table);
 
       return TRUE;
     }
@@ -517,7 +525,7 @@ g_hash_table_foreach_remove_or_steal (GHashTable *hash_table,
        }
     }
   
-  g_hash_table_resize (hash_table);
+  G_HASH_TABLE_RESIZE (hash_table);
   
   return deleted;
 }
@@ -570,17 +578,10 @@ g_hash_table_resize (GHashTable *hash_table)
   GHashNode **new_nodes;
   GHashNode *node;
   GHashNode *next;
-  gfloat nodes_per_list;
   guint hash_val;
   gint new_size;
   gint i;
-  
-  nodes_per_list = (gfloat) hash_table->nnodes / (gfloat) hash_table->size;
-  
-  if ((nodes_per_list > 0.3 || hash_table->size <= HASH_TABLE_MIN_SIZE) &&
-      (nodes_per_list < 3.0 || hash_table->size >= HASH_TABLE_MAX_SIZE))
-    return;
-  
+
   new_size = CLAMP(g_spaced_primes_closest (hash_table->nnodes),
                   HASH_TABLE_MIN_SIZE,
                   HASH_TABLE_MAX_SIZE);
index 6ad056a..b55bb6b 100644 (file)
@@ -1944,7 +1944,9 @@ g_main_context_prepare (GMainContext *context,
  * 
  * Determines information necessary to poll this main loop.
  * 
- * Return value: 
+ * Return value: the number of records actually stored in @fds,
+ *   or, if more than @n_fds records need to be stored, the number
+ *   of records that need to be stored.
  **/
 gint
 g_main_context_query (GMainContext *context,