summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2015-09-07 20:54:01 -0400
committerMatthias Clasen <mclasen@redhat.com>2015-09-07 20:54:01 -0400
commit41c0d15a6d680738e80a59e89c1058a97ca922ea (patch)
tree79ff7a021afd6f8a9b4918adb8cd654f8c3c5bd7
parenta62ad79f5c59152d1a52c3b52d969c3c48390cda (diff)
downloadglib-41c0d15a6d680738e80a59e89c1058a97ca922ea.tar.gz
Add a method to get the pspec name quark
This lets us avoid the quark lookup in the hot property change notification path.
-rw-r--r--docs/reference/gobject/gobject-sections.txt1
-rw-r--r--gobject/gparam.c34
-rw-r--r--gobject/gparam.h3
3 files changed, 35 insertions, 3 deletions
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index ad31c2313..b9f26c9a4 100644
--- a/docs/reference/gobject/gobject-sections.txt
+++ b/docs/reference/gobject/gobject-sections.txt
@@ -513,6 +513,7 @@ g_param_value_validate
g_param_value_convert
g_param_values_cmp
g_param_spec_get_name
+g_param_spec_get_name_quark
g_param_spec_get_nick
g_param_spec_get_blurb
g_param_spec_get_qdata
diff --git a/gobject/gparam.c b/gobject/gparam.c
index ec86766b4..681e1bf23 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -81,6 +81,7 @@ static gchar* value_param_lcopy_value (const GValue *value,
typedef struct
{
GValue default_value;
+ GQuark name_quark;
} GParamSpecPrivate;
static gint g_param_private_offset;
@@ -426,6 +427,7 @@ g_param_spec_internal (GType param_type,
GParamFlags flags)
{
GParamSpec *pspec;
+ GParamSpecPrivate *priv;
g_return_val_if_fail (G_TYPE_IS_PARAM (param_type) && param_type != G_TYPE_PARAM, NULL);
g_return_val_if_fail (name != NULL, NULL);
@@ -454,6 +456,9 @@ g_param_spec_internal (GType param_type,
}
}
+ priv = g_param_spec_get_private (pspec);
+ priv->name_quark = g_quark_from_string (pspec->name);
+
if (flags & G_PARAM_STATIC_NICK)
pspec->_nick = (gchar*) nick;
else
@@ -1520,11 +1525,11 @@ g_value_dup_param (const GValue *value)
/**
* g_param_spec_get_default_value:
- * @param: a #GParamSpec
+ * @pspec: a #GParamSpec
*
- * Gets the default value of @param as a pointer to a #GValue.
+ * Gets the default value of @pspec as a pointer to a #GValue.
*
- * The #GValue will remain value for the life of @param.
+ * The #GValue will remain value for the life of @pspec.
*
* Returns: a pointer to a #GValue which must not be modified
*
@@ -1564,3 +1569,26 @@ g_param_spec_get_default_value (GParamSpec *pspec)
return &priv->default_value;
}
+
+/**
+ * g_param_spec_get_name_quark:
+ * @param: a #GParamSpec
+ *
+ * Gets the GQuark for the name.
+ *
+ * Returns: the GQuark for @pspec->name.
+ *
+ * Since: 2.38
+ */
+GQuark
+g_param_spec_get_name_quark (GParamSpec *pspec)
+{
+ GParamSpecPrivate *priv = g_param_spec_get_private (pspec);
+
+ /* Return the quark that we've stashed away at creation time.
+ * This lets us avoid a lock and a hash table lookup when
+ * dispatching property change notification.
+ */
+
+ return priv->name_quark;
+}
diff --git a/gobject/gparam.h b/gobject/gparam.h
index 88b18fdd2..612624c29 100644
--- a/gobject/gparam.h
+++ b/gobject/gparam.h
@@ -343,6 +343,9 @@ void g_value_set_param_take_ownership (GValue *value,
GLIB_AVAILABLE_IN_2_36
const GValue * g_param_spec_get_default_value (GParamSpec *param);
+GLIB_AVAILABLE_IN_2_46
+GQuark g_param_spec_get_name_quark (GParamSpec *param);
+
/* --- convenience functions --- */
typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
/**