[gtk/wip/matthiasc/css-change: 1/27] css: Compute selector tree changes ahead of time



commit 7a5ab6eea0af6b417a47d6bb61f950e79ac69053
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 12 00:53:51 2020 -0500

    css: Compute selector tree changes ahead of time
    
    These only depend on the selector tree, so we can
    compute them while constructing the tree.

 gtk/gtkcssselector.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index b6468bd282..2b7461e5eb 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -104,6 +104,7 @@ union _GtkCssSelector
 struct _GtkCssSelectorTree
 {
   GtkCssSelector selector;
+  GtkCssChange change;
   gint32 parent_offset;
   gint32 previous_offset;
   gint32 sibling_offset;
@@ -1874,7 +1875,7 @@ gtk_css_selector_tree_get_change (const GtkCssSelectorTree *tree,
     return 0;
 
   if (!tree->selector.class->is_simple)
-    return gtk_css_selector_tree_collect_change (tree) | GTK_CSS_CHANGE_GOT_MATCH;
+    return tree->change | GTK_CSS_CHANGE_GOT_MATCH;
 
   for (prev = gtk_css_selector_tree_get_previous (tree);
        prev != NULL;
@@ -2084,6 +2085,7 @@ subdivide_infos (GByteArray *array, GList *infos, gint32 parent_offset)
   remaining = NULL;
 
   tree = alloc_tree (array, &tree_offset);
+  tree->change = 0;
   tree->parent_offset = parent_offset;
   tree->selector = max_selector;
 
@@ -2193,6 +2195,20 @@ fixup_offsets (GtkCssSelectorTree *tree, guint8 *data)
     }
 }
 
+static void
+compute_change (GtkCssSelectorTree *tree)
+{
+  for (; tree != NULL;
+       tree = (GtkCssSelectorTree *)gtk_css_selector_tree_get_sibling (tree))
+    {
+      GtkCssSelectorTree *prev = (GtkCssSelectorTree *)gtk_css_selector_tree_get_previous (tree);
+
+      tree->change = gtk_css_selector_tree_collect_change (tree);
+
+      compute_change (prev);
+    }
+}
+
 GtkCssSelectorTree *
 _gtk_css_selector_tree_builder_build (GtkCssSelectorTreeBuilder *builder)
 {
@@ -2216,6 +2232,8 @@ _gtk_css_selector_tree_builder_build (GtkCssSelectorTreeBuilder *builder)
 
   fixup_offsets (tree, data);
 
+  compute_change (tree);
+
   /* Convert offsets to final pointers */
   for (l = builder->infos; l != NULL; l = l->next)
     {


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