From 56e4ffabea547d2ea9ffa90c5bc9e0aece40749c Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 4 Aug 2010 13:11:50 +0200 Subject: [PATCH] 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 323f397a9c..0f55a862fd 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 60dcfa2371..db9f79b1be 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); +} - elem->name = g_strdup (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; + + return gtk_widget_path_iter_has_qname (path, pos, qname); } void diff --git a/gtk/gtkwidgetpath.h b/gtk/gtkwidgetpath.h index d6e074edec..e4c1de1579 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,