From: Benjamin Otte Date: Tue, 17 May 2011 12:58:39 +0000 (+0200) Subject: gobject: Speed up g_type_from_name() X-Git-Tag: 2.29.6~126 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d9440687ff13bd36b8c5696ce84327999589d04e;p=platform%2Fupstream%2Fglib.git gobject: Speed up g_type_from_name() The hash table used exclusively for looking up types by name used to map quarks => types. But we can easily make it map strings => types, which avoids the quark lookup. And that in trun avoids taking a lock and consulting another hash table. So this change should make g_type_from_name() roughly twice as fast. --- diff --git a/gobject/gtype.c b/gobject/gtype.c index 9439939..088a86a 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -81,10 +81,6 @@ * not ->supers[]), as all those memory portions can get realloc()ed during * callback invocation. * - * TODO: - * - g_type_from_name() should do an ordered array lookup after fetching the - * the quark, instead of a second hashtable lookup. - * * LOCKING: * lock handling issues when calling static functions are indicated by * uppercase letter postfixes, all static functions have to have @@ -492,7 +488,7 @@ type_node_any_new_W (TypeNode *pnode, node->global_gdata = NULL; g_hash_table_insert (static_type_nodes_ht, - GUINT_TO_POINTER (node->qname), + g_quark_to_string (node->qname), (gpointer) type); return node; } @@ -3328,13 +3324,9 @@ g_type_from_name (const gchar *name) g_return_val_if_fail (name != NULL, 0); - quark = g_quark_try_string (name); - if (quark) - { - G_READ_LOCK (&type_rw_lock); - type = (GType) g_hash_table_lookup (static_type_nodes_ht, GUINT_TO_POINTER (quark)); - G_READ_UNLOCK (&type_rw_lock); - } + G_READ_LOCK (&type_rw_lock); + type = (GType) g_hash_table_lookup (static_type_nodes_ht, name); + G_READ_UNLOCK (&type_rw_lock); return type; } @@ -4308,7 +4300,7 @@ g_type_init_with_debug_flags (GTypeDebugFlags debug_flags) static_quark_dependants_array = g_quark_from_static_string ("-g-type-private--dependants-array"); /* type qname hash table */ - static_type_nodes_ht = g_hash_table_new (g_direct_hash, g_direct_equal); + static_type_nodes_ht = g_hash_table_new (g_str_hash, g_str_equal); /* invalid type G_TYPE_INVALID (0) */