mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
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.
This commit is contained in:
parent
aeac5de2f8
commit
d9440687ff
@ -81,10 +81,6 @@
|
|||||||
* not ->supers[]), as all those memory portions can get realloc()ed during
|
* not ->supers[]), as all those memory portions can get realloc()ed during
|
||||||
* callback invocation.
|
* 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:
|
* LOCKING:
|
||||||
* lock handling issues when calling static functions are indicated by
|
* lock handling issues when calling static functions are indicated by
|
||||||
* uppercase letter postfixes, all static functions have to have
|
* uppercase letter postfixes, all static functions have to have
|
||||||
@ -492,7 +488,7 @@ type_node_any_new_W (TypeNode *pnode,
|
|||||||
node->global_gdata = NULL;
|
node->global_gdata = NULL;
|
||||||
|
|
||||||
g_hash_table_insert (static_type_nodes_ht,
|
g_hash_table_insert (static_type_nodes_ht,
|
||||||
GUINT_TO_POINTER (node->qname),
|
g_quark_to_string (node->qname),
|
||||||
(gpointer) type);
|
(gpointer) type);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -3328,13 +3324,9 @@ g_type_from_name (const gchar *name)
|
|||||||
|
|
||||||
g_return_val_if_fail (name != NULL, 0);
|
g_return_val_if_fail (name != NULL, 0);
|
||||||
|
|
||||||
quark = g_quark_try_string (name);
|
G_READ_LOCK (&type_rw_lock);
|
||||||
if (quark)
|
type = (GType) g_hash_table_lookup (static_type_nodes_ht, name);
|
||||||
{
|
G_READ_UNLOCK (&type_rw_lock);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return type;
|
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");
|
static_quark_dependants_array = g_quark_from_static_string ("-g-type-private--dependants-array");
|
||||||
|
|
||||||
/* type qname hash table */
|
/* 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)
|
/* invalid type G_TYPE_INVALID (0)
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user