[glib] Make g_datalist_get_data not look up the quark
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Make g_datalist_get_data not look up the quark
- Date: Sat, 4 Jun 2011 01:14:42 +0000 (UTC)
commit 1cceda49b60bfd9b326e11996a5c77b10987e57a
Author: Alexander Larsson <alexl redhat com>
Date: Thu May 19 21:51:49 2011 +0200
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
glib/gdataset.c | 52 ++++++++++++++++++++++++++++++++++++++++++----------
glib/gdataset.h | 4 ++--
glib/glib.symbols | 1 +
3 files changed, 45 insertions(+), 12 deletions(-)
---
diff --git a/glib/gdataset.c b/glib/gdataset.c
index 661c30f..c2582b9 100644
--- a/glib/gdataset.c
+++ b/glib/gdataset.c
@@ -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)
@@ -823,6 +813,48 @@ g_datalist_id_get_data (GData **datalist,
}
/**
+ * 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.
* @data: the data element.
diff --git a/glib/gdataset.h b/glib/gdataset.h
index 2733ffb..4451c38 100644
--- a/glib/gdataset.h
+++ b/glib/gdataset.h
@@ -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,
diff --git a/glib/glib.symbols b/glib/glib.symbols
index d38450d..d8a18b9 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]