mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Make g_datalist_get_data not look up the quark
Instead of converting the string to a quark and comparing quarks we use the new lockless g_quark_to_string and just compare the quarks in the datalist with the given string. This means we avoid the global lock for string to quark. Additionally most of the time the data list will be quite short, so the cost of doing the sting comparisons is likely similar to that of the quark hashtable lookup (which does at least one string comparison for a successfull lookup). https://bugzilla.gnome.org/show_bug.cgi?id=650458
This commit is contained in:
parent
7ae5e9c248
commit
1cceda49b6
@ -776,16 +776,6 @@ g_dataset_id_get_data (gconstpointer dataset_location,
|
||||
*
|
||||
* Retrieves the data element corresponding to @key_id.
|
||||
**/
|
||||
/**
|
||||
* g_datalist_get_data:
|
||||
* @dl: a datalist.
|
||||
* @k: the string identifying a data element.
|
||||
* @Returns: the data element, or %NULL if it is not found.
|
||||
*
|
||||
* Gets a data element, using its string identifer. This is slower than
|
||||
* g_datalist_id_get_data() because the string is first converted to a
|
||||
* #GQuark.
|
||||
**/
|
||||
gpointer
|
||||
g_datalist_id_get_data (GData **datalist,
|
||||
GQuark key_id)
|
||||
@ -822,6 +812,48 @@ g_datalist_id_get_data (GData **datalist,
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_datalist_get_data:
|
||||
* @dl: a datalist.
|
||||
* @k: the string identifying a data element.
|
||||
* @Returns: the data element, or %NULL if it is not found.
|
||||
*
|
||||
* Gets a data element, using its string identifer. This is slower than
|
||||
* g_datalist_id_get_data() because it compares strings.
|
||||
**/
|
||||
gpointer
|
||||
g_datalist_get_data (GData **datalist,
|
||||
const gchar *key)
|
||||
{
|
||||
gpointer res = NULL;
|
||||
GData *d;
|
||||
GDataElt *data, *data_end;
|
||||
|
||||
g_return_val_if_fail (datalist != NULL, NULL);
|
||||
|
||||
g_datalist_lock (datalist);
|
||||
|
||||
d = G_DATALIST_GET_POINTER (datalist);
|
||||
if (d)
|
||||
{
|
||||
data = d->data;
|
||||
data_end = data + d->len;
|
||||
while (data < data_end)
|
||||
{
|
||||
if (strcmp (g_quark_to_string (data->key), key) == 0)
|
||||
{
|
||||
res = data->data;
|
||||
break;
|
||||
}
|
||||
data++;
|
||||
}
|
||||
}
|
||||
|
||||
g_datalist_unlock (datalist);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* GDataForeachFunc:
|
||||
* @key_id: the #GQuark id to identifying the data element.
|
||||
|
@ -76,8 +76,6 @@ guint g_datalist_get_flags (GData **datalist);
|
||||
g_datalist_id_set_data_full ((dl), (q), (d), NULL)
|
||||
#define g_datalist_id_remove_data(dl, q) \
|
||||
g_datalist_id_set_data ((dl), (q), NULL)
|
||||
#define g_datalist_get_data(dl, k) \
|
||||
(g_datalist_id_get_data ((dl), g_quark_try_string (k)))
|
||||
#define g_datalist_set_data_full(dl, k, d, f) \
|
||||
g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
|
||||
#define g_datalist_remove_no_notify(dl, k) \
|
||||
@ -93,6 +91,8 @@ guint g_datalist_get_flags (GData **datalist);
|
||||
void g_dataset_destroy (gconstpointer dataset_location);
|
||||
gpointer g_dataset_id_get_data (gconstpointer dataset_location,
|
||||
GQuark key_id);
|
||||
gpointer g_datalist_get_data (GData **datalist,
|
||||
const gchar *key);
|
||||
void g_dataset_id_set_data_full (gconstpointer dataset_location,
|
||||
GQuark key_id,
|
||||
gpointer data,
|
||||
|
@ -184,6 +184,7 @@ g_filename_to_utf8_utf8
|
||||
g_uri_list_extract_uris
|
||||
g_datalist_clear
|
||||
g_datalist_foreach
|
||||
g_datalist_get_data
|
||||
g_datalist_get_flags
|
||||
g_datalist_id_get_data
|
||||
g_datalist_id_remove_no_notify
|
||||
|
Loading…
Reference in New Issue
Block a user