[gtk/wip/baedert/for-master: 9/20] cssmatcher: Inline node values into matcher



commit df1cceb96aeb7c1e6a5cc5b69a780c3a21e93597
Author: Timm Bäder <mail baedert org>
Date:   Wed Aug 21 11:18:22 2019 +0200

    cssmatcher: Inline node values into matcher
    
    So we don't have to go through the matcher->node->decl every time

 gtk/gtkcssmatcher.c        | 39 +++++++++++++++++++++++++++++++++++----
 gtk/gtkcssmatcherprivate.h |  5 +++++
 2 files changed, 40 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index 8afdab1b26..899a7f74f6 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -237,21 +237,47 @@ gtk_css_matcher_node_get_previous (GtkCssMatcher       *matcher,
 static GtkStateFlags
 gtk_css_matcher_node_get_state (const GtkCssMatcher *matcher)
 {
-  return gtk_css_node_get_state (matcher->node.node);
+  return matcher->node.node_state;
 }
 
 static gboolean
 gtk_css_matcher_node_has_name (const GtkCssMatcher     *matcher,
                                /*interned*/ const char *name)
 {
-  return gtk_css_node_get_name (matcher->node.node) == name;
+  return matcher->node.node_name == name;
 }
 
 static gboolean
 gtk_css_matcher_node_has_class (const GtkCssMatcher *matcher,
                                 GQuark               class_name)
 {
-  return gtk_css_node_has_class (matcher->node.node, class_name);
+  const GQuark *classes = matcher->node.classes;
+
+  switch (matcher->node.n_classes)
+    {
+    case 3:
+      if (classes[2] == class_name)
+        return TRUE;
+      G_GNUC_FALLTHROUGH;
+
+    case 2:
+      if (classes[1] == class_name)
+        return TRUE;
+      G_GNUC_FALLTHROUGH;
+
+    case 1:
+      if (classes[0] == class_name)
+        return TRUE;
+      G_GNUC_FALLTHROUGH;
+
+    case 0:
+      return FALSE;
+
+    default:
+      return gtk_css_node_has_class (matcher->node.node, class_name);
+    }
+
+  return FALSE;
 }
 
 static gboolean
@@ -259,7 +285,7 @@ gtk_css_matcher_node_has_id (const GtkCssMatcher *matcher,
                              const char          *id)
 {
   /* assume all callers pass an interned string */
-  return gtk_css_node_get_id (matcher->node.node) == id;
+  return matcher->node.node_id == id;
 }
 
 static gboolean
@@ -325,6 +351,11 @@ _gtk_css_matcher_node_init (GtkCssMatcher *matcher,
 {
   matcher->node.klass = &GTK_CSS_MATCHER_NODE;
   matcher->node.node = node;
+  matcher->node.node_state = gtk_css_node_get_state (node);
+  matcher->node.node_name = gtk_css_node_get_name (node);
+  matcher->node.node_id = gtk_css_node_get_id (node);
+  matcher->node.classes = gtk_css_node_declaration_get_classes (gtk_css_node_get_declaration (node),
+                                                                &matcher->node.n_classes);
 }
 
 /* GTK_CSS_MATCHER_WIDGET_ANY */
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index 29890a84c5..a78f777abb 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -60,6 +60,11 @@ struct _GtkCssMatcherWidgetPath {
 struct _GtkCssMatcherNode {
   const GtkCssMatcherClass *klass;
   GtkCssNode               *node;
+  GtkStateFlags             node_state;
+  const char               *node_name;
+  const char               *node_id;
+  const GQuark             *classes;
+  guint                     n_classes;
 };
 
 struct _GtkCssMatcherSuperset {


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