[gtk+/gtk-style-context: 173/206] Compare region names as quarks in style matching.



commit 0a0dd70c792dad0064d8e71c81377328a8de61fd
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Aug 4 12:19:23 2010 +0200

    Compare region names as quarks in style matching.

 gtk/gtkcssprovider.c |    8 ++---
 gtk/gtkwidgetpath.c  |   67 +++++++++++++++++++++++++++++++++++---------------
 gtk/gtkwidgetpath.h  |    4 +++
 3 files changed, 54 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 9ebac41..75cbd30 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -411,13 +411,11 @@ compare_selector_element (GtkWidgetPath   *path,
     }
   else if (elem->elem_type == SELECTOR_REGION)
     {
-      const gchar *region_name;
       GtkChildClassFlags flags;
 
-      /* FIXME: Need GQuark API here */
-      region_name = g_quark_to_string (elem->region.name);
-
-      if (!gtk_widget_path_iter_has_region (path, index, region_name, &flags))
+      if (!gtk_widget_path_iter_has_qregion (path, index,
+                                             elem->region.name,
+                                             &flags))
         return FALSE;
 
       if (elem->region.flags != 0 &&
diff --git a/gtk/gtkwidgetpath.c b/gtk/gtkwidgetpath.c
index 29b019e..bbac2a7 100644
--- a/gtk/gtkwidgetpath.c
+++ b/gtk/gtkwidgetpath.c
@@ -74,15 +74,10 @@ gtk_widget_path_copy (const GtkWidgetPath *path)
           gpointer key, value;
 
           g_hash_table_iter_init (&iter, elem->regions);
-          new.regions = g_hash_table_new_full (g_str_hash,
-                                               g_str_equal,
-                                               (GDestroyNotify) g_free,
-                                               NULL);
+          new.regions = g_hash_table_new (NULL, NULL);
 
           while (g_hash_table_iter_next (&iter, &key, &value))
-            g_hash_table_insert (new.regions,
-                                 g_strdup ((const gchar *) key),
-                                 value);
+            g_hash_table_insert (new.regions, key, value);
         }
 
       g_array_append_val (new_path->elems, new);
@@ -203,21 +198,20 @@ gtk_widget_path_iter_add_region (GtkWidgetPath      *path,
                                  GtkChildClassFlags  flags)
 {
   GtkPathElement *elem;
+  GQuark qname;
 
   g_return_if_fail (path != NULL);
   g_return_if_fail (pos < path->elems->len);
   g_return_if_fail (name != NULL);
 
   elem = &g_array_index (path->elems, GtkPathElement, pos);
+  qname = g_quark_from_string (name);
 
   if (!elem->regions)
-    elem->regions = g_hash_table_new_full (g_str_hash,
-                                           g_str_equal,
-                                           (GDestroyNotify) g_free,
-                                           NULL);
+    elem->regions = g_hash_table_new (NULL, NULL);
 
   g_hash_table_insert (elem->regions,
-                       g_strdup (name),
+                       GUINT_TO_POINTER (qname),
                        GUINT_TO_POINTER (flags));
 }
 
@@ -227,15 +221,21 @@ gtk_widget_path_iter_remove_region (GtkWidgetPath *path,
                                     const gchar   *name)
 {
   GtkPathElement *elem;
+  GQuark qname;
 
   g_return_if_fail (path != NULL);
   g_return_if_fail (pos < path->elems->len);
   g_return_if_fail (name != NULL);
 
+  qname = g_quark_try_string (name);
+
+  if (qname == 0)
+    return;
+
   elem = &g_array_index (path->elems, GtkPathElement, pos);
 
   if (elem->regions)
-    g_hash_table_remove (elem->regions, name);
+    g_hash_table_remove (elem->regions, GUINT_TO_POINTER (qname));
 }
 
 void
@@ -273,30 +273,37 @@ gtk_widget_path_iter_list_regions (const GtkWidgetPath *path,
   g_hash_table_iter_init (&iter, elem->regions);
 
   while (g_hash_table_iter_next (&iter, &key, NULL))
-    list = g_slist_prepend (list, key);
+    {
+      GQuark qname;
+
+      qname = GPOINTER_TO_UINT (key);
+      list = g_slist_prepend (list, (gchar *) g_quark_to_string (qname));
+    }
 
   return list;
 }
 
 gboolean
-gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
-                                 guint                pos,
-                                 const gchar         *name,
-                                 GtkChildClassFlags  *flags)
+gtk_widget_path_iter_has_qregion (const GtkWidgetPath *path,
+                                  guint                pos,
+                                  GQuark               qname,
+                                  GtkChildClassFlags  *flags)
 {
   GtkPathElement *elem;
   gpointer value;
 
   g_return_val_if_fail (path != NULL, FALSE);
   g_return_val_if_fail (pos < path->elems->len, FALSE);
-  g_return_val_if_fail (name != NULL, FALSE);
+  g_return_val_if_fail (qname != 0, FALSE);
 
   elem = &g_array_index (path->elems, GtkPathElement, pos);
 
   if (!elem->regions)
     return FALSE;
 
-  if (!g_hash_table_lookup_extended (elem->regions, name, NULL, &value))
+  if (!g_hash_table_lookup_extended (elem->regions,
+                                     GUINT_TO_POINTER (qname),
+                                     NULL, &value))
     return FALSE;
 
   if (flags)
@@ -305,6 +312,26 @@ gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
   return TRUE;
 }
 
+gboolean
+gtk_widget_path_iter_has_region (const GtkWidgetPath *path,
+                                 guint                pos,
+                                 const gchar         *name,
+                                 GtkChildClassFlags  *flags)
+{
+  GQuark qname;
+
+  g_return_val_if_fail (path != NULL, FALSE);
+  g_return_val_if_fail (pos < path->elems->len, FALSE);
+  g_return_val_if_fail (name != NULL, FALSE);
+
+  qname = g_quark_try_string (name);
+
+  if (qname == 0)
+    return FALSE;
+
+  return gtk_widget_path_iter_has_qregion (path, pos, qname, flags);
+}
+
 GType
 gtk_widget_path_get_widget_type (const GtkWidgetPath *path)
 {
diff --git a/gtk/gtkwidgetpath.h b/gtk/gtkwidgetpath.h
index 78c33e0..b6515e1 100644
--- a/gtk/gtkwidgetpath.h
+++ b/gtk/gtkwidgetpath.h
@@ -67,6 +67,10 @@ gboolean gtk_widget_path_iter_has_region    (const GtkWidgetPath *path,
                                              guint                pos,
                                              const gchar         *name,
                                              GtkChildClassFlags  *flags);
+gboolean gtk_widget_path_iter_has_qregion   (const GtkWidgetPath *path,
+                                             guint                pos,
+                                             GQuark               qname,
+                                             GtkChildClassFlags  *flags);
 
 GType           gtk_widget_path_get_widget_type (const GtkWidgetPath *path);
 



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