[glib] GParamSpec: intern property names



commit d6c30e1766c975dd79e6f252d73c6c0581b64b01
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jul 14 18:08:25 2011 +0200

    GParamSpec: intern property names
    
    Make it so that the ->name property on all GParamSpec objects is an
    interned string.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=654627

 gobject/gparam.c |   18 ++++++++++++------
 gobject/gparam.h |    2 +-
 2 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/gobject/gparam.c b/gobject/gparam.c
index cc84581..5e9ffe0 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -173,9 +173,6 @@ g_param_spec_finalize (GParamSpec *pspec)
 {
   g_datalist_clear (&pspec->qdata);
 
-  if (!(pspec->flags & G_PARAM_STATIC_NAME))
-    g_free (pspec->name);
-  
   if (!(pspec->flags & G_PARAM_STATIC_NICK))
     g_free (pspec->_nick);
 
@@ -275,6 +272,9 @@ g_param_spec_ref_sink (GParamSpec *pspec)
  *
  * Get the name of a #GParamSpec.
  *
+ * The name is always an "interned" string (as per g_intern_string()).
+ * This allows for pointer-value comparisons.
+ *
  * Returns: the name of @pspec.
  */
 const gchar *
@@ -428,9 +428,15 @@ g_param_spec_internal (GType        param_type,
     }
   else
     {
-      pspec->name = g_strdup (name);
-      canonicalize_key (pspec->name);
-      g_intern_string (pspec->name);
+      if (is_canonical (name))
+        pspec->name = (gchar *) g_intern_string (name);
+      else
+        {
+          gchar *tmp = g_strdup (name);
+          canonicalize_key (tmp);
+          pspec->name = (gchar *) g_intern_string (tmp);
+          g_free (tmp);
+        }
     }
 
   if (flags & G_PARAM_STATIC_NICK)
diff --git a/gobject/gparam.h b/gobject/gparam.h
index 5ee41ab..8f5c04f 100644
--- a/gobject/gparam.h
+++ b/gobject/gparam.h
@@ -193,7 +193,7 @@ typedef struct _GParamSpecPool  GParamSpecPool;
 /**
  * GParamSpec:
  * @g_type_instance: private #GTypeInstance portion
- * @name: name of this parameter
+ * @name: name of this parameter: always an interned string
  * @flags: #GParamFlags flags for this parameter
  * @value_type: the #GValue type for this parameter
  * @owner_type: #GType type that uses (introduces) this parameter



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]