[gtk+/gtk-style-context: 177/191] Compare widget names as GQuarks in style matching.



commit 5a9caaf2c549518bd96351d00b09c1a310220ceb
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Aug 4 13:11:50 2010 +0200

    Compare widget names as GQuarks in style matching.

 gtk/gtkcssprovider.c |    8 +-------
 gtk/gtkwidgetpath.c  |   45 ++++++++++++++++++++++++++++++++++++++-------
 gtk/gtkwidgetpath.h  |   16 +++++++++++-----
 3 files changed, 50 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 2e23d57..c98a6eb 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -433,13 +433,7 @@ compare_selector_element (GtkWidgetPath   *path,
     }
   else if (elem->elem_type == SELECTOR_NAME)
     {
-      const gchar *name, *path_name;
-
-      name = g_quark_to_string (elem->name);
-      path_name = gtk_widget_path_iter_get_name (path, index);
-
-      if (!path_name ||
-          strcmp (path_name, name) != 0)
+      if (!gtk_widget_path_iter_has_qname (path, index, elem->name))
         return FALSE;
 
       *score = 0xF;
diff --git a/gtk/gtkwidgetpath.c b/gtk/gtkwidgetpath.c
index 60dcfa2..db9f79b 100644
--- a/gtk/gtkwidgetpath.c
+++ b/gtk/gtkwidgetpath.c
@@ -29,7 +29,7 @@ typedef struct GtkPathElement GtkPathElement;
 struct GtkPathElement
 {
   GType type;
-  gchar *name;
+  GQuark name;
   GHashTable *regions;
 };
 
@@ -66,7 +66,7 @@ gtk_widget_path_copy (const GtkWidgetPath *path)
       elem = &g_array_index (path->elems, GtkPathElement, i);
 
       new.type = elem->type;
-      new.name = g_strdup (elem->name);
+      new.name = elem->name;
 
       if (elem->regions)
         {
@@ -98,7 +98,6 @@ gtk_widget_path_free (GtkWidgetPath *path)
       GtkPathElement *elem;
 
       elem = &g_array_index (path->elems, GtkPathElement, i);
-      g_free (elem->name);
 
       if (elem->regions)
         g_hash_table_destroy (elem->regions);
@@ -169,7 +168,7 @@ gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
   g_return_val_if_fail (pos < path->elems->len, NULL);
 
   elem = &g_array_index (path->elems, GtkPathElement, pos);
-  return elem->name;
+  return g_quark_to_string (elem->name);
 }
 
 void
@@ -185,10 +184,42 @@ gtk_widget_path_iter_set_name (GtkWidgetPath *path,
 
   elem = &g_array_index (path->elems, GtkPathElement, pos);
 
-  if (elem->name)
-    g_free (elem->name);
+  elem->name = g_quark_from_string (name);
+}
+
+gboolean
+gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
+                                guint                pos,
+                                GQuark               qname)
+{
+  GtkPathElement *elem;
+
+  g_return_val_if_fail (path != NULL, FALSE);
+  g_return_val_if_fail (qname != 0, FALSE);
+  g_return_val_if_fail (pos < path->elems->len, FALSE);
+
+  elem = &g_array_index (path->elems, GtkPathElement, pos);
+
+  return (elem->name == qname);
+}
+
+gboolean
+gtk_widget_path_iter_has_name (const GtkWidgetPath *path,
+                               guint                pos,
+                               const gchar         *name)
+{
+  GQuark qname;
+
+  g_return_val_if_fail (path != NULL, FALSE);
+  g_return_val_if_fail (name != NULL, FALSE);
+  g_return_val_if_fail (pos < path->elems->len, FALSE);
+
+  qname = g_quark_try_string (name);
+
+  if (qname == 0)
+    return FALSE;
 
-  elem->name = g_strdup (name);
+  return gtk_widget_path_iter_has_qname (path, pos, qname);
 }
 
 void
diff --git a/gtk/gtkwidgetpath.h b/gtk/gtkwidgetpath.h
index d6e074e..e4c1de1 100644
--- a/gtk/gtkwidgetpath.h
+++ b/gtk/gtkwidgetpath.h
@@ -44,11 +44,17 @@ void                gtk_widget_path_iter_set_widget_type (GtkWidgetPath       *p
                                                           guint                pos,
                                                           GType                type);
 
-G_CONST_RETURN gchar * gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
-                                                      guint                pos);
-void                   gtk_widget_path_iter_set_name (GtkWidgetPath       *path,
-                                                      guint                pos,
-                                                      const gchar         *name);
+G_CONST_RETURN gchar * gtk_widget_path_iter_get_name  (const GtkWidgetPath *path,
+                                                       guint                pos);
+void                   gtk_widget_path_iter_set_name  (GtkWidgetPath       *path,
+                                                       guint                pos,
+                                                       const gchar         *name);
+gboolean               gtk_widget_path_iter_has_name  (const GtkWidgetPath *path,
+                                                       guint                pos,
+                                                       const gchar         *name);
+gboolean               gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
+                                                       guint                pos,
+                                                       GQuark               qname);
 
 void     gtk_widget_path_iter_add_region    (GtkWidgetPath      *path,
                                              guint               pos,



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