split attribute hash initialization into its own function

This commit is contained in:
Benjamin Otte 2009-06-29 13:21:08 +02:00
parent 49172a71aa
commit 66cebd7292

View File

@ -140,6 +140,16 @@ _lookup_namespace (const char *namespace)
return ns_info; return ns_info;
} }
static void
ensure_attribute_hash (void)
{
if (attribute_hash != NULL)
return;
ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
static guint32 static guint32
lookup_namespace (const char *namespace) lookup_namespace (const char *namespace)
{ {
@ -148,11 +158,7 @@ lookup_namespace (const char *namespace)
G_LOCK (attribute_hash); G_LOCK (attribute_hash);
if (attribute_hash == NULL) ensure_attribute_hash ();
{
ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
ns_info = _lookup_namespace (namespace); ns_info = _lookup_namespace (namespace);
id = 0; id = 0;
@ -183,11 +189,7 @@ lookup_attribute (const char *attribute)
NSInfo *ns_info; NSInfo *ns_info;
G_LOCK (attribute_hash); G_LOCK (attribute_hash);
if (attribute_hash == NULL) ensure_attribute_hash ();
{
ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute)); attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute));