[glib] Add a method to get the pspec name quark
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add a method to get the pspec name quark
- Date: Tue, 8 Sep 2015 00:58:17 +0000 (UTC)
commit 41c0d15a6d680738e80a59e89c1058a97ca922ea
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Sep 7 20:54:01 2015 -0400
Add a method to get the pspec name quark
This lets us avoid the quark lookup in the hot
property change notification path.
docs/reference/gobject/gobject-sections.txt | 1 +
gobject/gparam.c | 34 ++++++++++++++++++++++++--
gobject/gparam.h | 3 ++
3 files changed, 35 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index ad31c23..b9f26c9 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 ec86766..681e1bf 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 88b18fd..612624c 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;
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]