[gtk+/parser] xxx: Revert "css: Make selector by type matching not require g_type_from_name()"



commit 34cbef4cc3ee43d376475d1e83f345ac9ce878d7
Author: Benjamin Otte <otte redhat com>
Date:   Tue May 17 17:04:46 2011 +0200

    xxx: Revert "css: Make selector by type matching not require g_type_from_name()"
    
    This reverts commit b02ec172bcfa059c9ad8cbc5745fb8662aa4b9a2. The commit
    was broken (didn't check interfaces) and after fixing g_type_from_name()
    the old code is actually twice as fast.

 gtk/gtkcssselector.c |   38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 24d3e9b..35db9ca 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -21,11 +21,14 @@
 
 #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 */
-  GQuark            name;            /* quarked name of element we match or 0 if any */
+  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 *          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 */
@@ -46,7 +49,8 @@ _gtk_css_selector_new (GtkCssSelector         *previous,
   selector = g_slice_new0 (GtkCssSelector);
   selector->previous = previous;
   selector->combine = combine;
-  selector->name = name ? g_quark_from_string (name) : 0;
+  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->ids = ids;
   selector->classes = classes;
   selector->pseudo_classes = pseudo_classes;
@@ -90,7 +94,7 @@ _gtk_css_selector_print (const GtkCssSelector *selector,
     }
 
   if (selector->name)
-    g_string_append (str, g_quark_to_string (selector->name));
+    g_string_append (str, selector->name);
   else if (selector->ids == NULL && 
            selector->classes == NULL && 
            selector->pseudo_classes == 0 &&
@@ -182,21 +186,23 @@ gtk_css_selector_matches_type (const GtkCssSelector      *selector,
                                /* const */ GtkWidgetPath *path,
                                guint                      id)
 {
-  GType type;
-
-  if (selector->name == 0)
+  if (selector->name == NULL)
     return TRUE;
 
   if (selector->pseudo_classes)
     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;
-    }
+  if (selector->type == G_TYPE_NONE)
+    return FALSE;
 
-  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;
+
+  return g_type_is_a (gtk_widget_path_iter_get_object_type (path, id), selector->type);
 }
 
 static gboolean
@@ -206,16 +212,14 @@ gtk_css_selector_matches_region (const GtkCssSelector      *selector,
                                  const char *               region)
 {
   GtkRegionFlags flags;
-  GQuark qregion;
 
-  if (selector->name == 0)
+  if (selector->name == NULL)
     return TRUE;
   
-  qregion = g_quark_from_string (region);
-  if (selector->name != qregion)
+  if (selector->name != region)
     return FALSE;
 
-  if (!gtk_widget_path_iter_has_qregion (path, id, qregion, &flags))
+  if (!gtk_widget_path_iter_has_region (path, id, region, &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]