From: Owen Taylor Date: Mon, 20 Aug 2001 01:37:50 +0000 (+0000) Subject: Eliminate use of floating point when determining if the hash table needs X-Git-Tag: GLIB_1_3_7~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8079eb3456914a03618b92b48f75a71b25331acb;p=platform%2Fupstream%2Fglib.git Eliminate use of floating point when determining if the hash table needs Sun Aug 19 21:32:39 2001 Owen Taylor * 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. --- diff --git a/ChangeLog b/ChangeLog index 7bf7a77..e9e250f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Sun Aug 19 21:32:39 2001 Owen Taylor + + * 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 * glib/gshell.c: (g_shell_quote): Added missing \ character. diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 7bf7a77..e9e250f 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,14 @@ +Sun Aug 19 21:32:39 2001 Owen Taylor + + * 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 * glib/gshell.c: (g_shell_quote): Added missing \ character. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 7bf7a77..e9e250f 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +Sun Aug 19 21:32:39 2001 Owen Taylor + + * 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 * glib/gshell.c: (g_shell_quote): Added missing \ character. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 7bf7a77..e9e250f 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,14 @@ +Sun Aug 19 21:32:39 2001 Owen Taylor + + * 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 * glib/gshell.c: (g_shell_quote): Added missing \ character. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 7bf7a77..e9e250f 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,14 @@ +Sun Aug 19 21:32:39 2001 Owen Taylor + + * 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 * glib/gshell.c: (g_shell_quote): Added missing \ character. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 7bf7a77..e9e250f 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,14 @@ +Sun Aug 19 21:32:39 2001 Owen Taylor + + * 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 * glib/gshell.c: (g_shell_quote): Added missing \ character. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 7bf7a77..e9e250f 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +Sun Aug 19 21:32:39 2001 Owen Taylor + + * 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 * glib/gshell.c: (g_shell_quote): Added missing \ character. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 7bf7a77..e9e250f 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +Sun Aug 19 21:32:39 2001 Owen Taylor + + * 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 * glib/gshell.c: (g_shell_quote): Added missing \ character. diff --git a/glib/ghash.c b/glib/ghash.c index 62f4b95..28bc1c3 100644 --- a/glib/ghash.c +++ b/glib/ghash.c @@ -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); diff --git a/glib/gmain.c b/glib/gmain.c index 6ad056a..b55bb6b 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -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,