[gtk+/parser] css: Make selector by type matching not require g_type_from_name()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/parser] css: Make selector by type matching not require g_type_from_name()
- Date: Mon, 16 May 2011 16:00:01 +0000 (UTC)
commit b02ec172bcfa059c9ad8cbc5745fb8662aa4b9a2
Author: Benjamin Otte <otte redhat com>
Date: Mon May 16 15:27:38 2011 +0200
css: Make selector by type matching not require g_type_from_name()
This speeds thje code up quite a bit but contains a custom
implementation of g_type_is_a() that works by name.
gtk/gtkcssselector.c | 38 +++++++++++++++++---------------------
1 files changed, 17 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 3850a9e..8279385 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -21,14 +21,11 @@
#include "gtkcssselectorprivate.h"
-#include "gtkstylecontextprivate.h"
-
struct _GtkCssSelector
{
GtkCssSelector * previous; /* link to next element in selector or NULL if last */
GtkCssCombinator combine; /* how to combine with the previous element */
- const char * name; /* quarked name of element we match or NULL if any */
- GType type; /* cache for type belonging to name - G_TYPE_INVALID if uncached */
+ GQuark name; /* quarked name of element we match or 0 if any */
GQuark * ids; /* 0-terminated list of required ids or NULL if none */
GQuark * classes; /* 0-terminated list of required classes or NULL if none */
GtkRegionFlags pseudo_classes; /* required pseudo classes */
@@ -49,8 +46,7 @@ _gtk_css_selector_new (GtkCssSelector *previous,
selector = g_slice_new0 (GtkCssSelector);
selector->previous = previous;
selector->combine = combine;
- selector->name = name ? g_quark_to_string (g_quark_from_string (name)) : NULL;
- selector->type = !name || _gtk_style_context_check_region_name (name) ? G_TYPE_NONE : G_TYPE_INVALID;
+ selector->name = name ? g_quark_from_string (name) : 0;
selector->ids = ids;
selector->classes = classes;
selector->pseudo_classes = pseudo_classes;
@@ -94,7 +90,7 @@ _gtk_css_selector_print (const GtkCssSelector *selector,
}
if (selector->name)
- g_string_append (str, selector->name);
+ g_string_append (str, g_quark_to_string (selector->name));
else if (selector->ids == NULL &&
selector->classes == NULL &&
selector->pseudo_classes == 0 &&
@@ -186,23 +182,21 @@ gtk_css_selector_matches_type (const GtkCssSelector *selector,
/* const */ GtkWidgetPath *path,
guint id)
{
- if (selector->name == NULL)
+ GType type;
+
+ if (selector->name == 0)
return TRUE;
if (selector->pseudo_classes)
return FALSE;
- if (selector->type == G_TYPE_NONE)
- return FALSE;
-
- /* ugh, assigning to a const variable */
- if (selector->type == G_TYPE_INVALID)
- ((GtkCssSelector *) selector)->type = g_type_from_name (selector->name);
-
- if (selector->type == G_TYPE_INVALID)
- return FALSE;
+ for (type = gtk_widget_path_iter_get_object_type (path, id); type; type = g_type_parent (type))
+ {
+ if (g_type_qname (type) == selector->name)
+ return TRUE;
+ }
- return g_type_is_a (gtk_widget_path_iter_get_object_type (path, id), selector->type);
+ return FALSE;
}
static gboolean
@@ -212,14 +206,16 @@ gtk_css_selector_matches_region (const GtkCssSelector *selector,
const char * region)
{
GtkRegionFlags flags;
+ GQuark qregion;
- if (selector->name == NULL)
+ if (selector->name == 0)
return TRUE;
- if (selector->name != region)
+ qregion = g_quark_from_string (region);
+ if (selector->name != qregion)
return FALSE;
- if (!gtk_widget_path_iter_has_region (path, id, region, &flags))
+ if (!gtk_widget_path_iter_has_qregion (path, id, qregion, &flags))
{
/* This function must be called with existing regions */
g_assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]