[gtk/css-lookup-caching] css style: Use a linear sweep to compute values



commit afe99c4a36b9fb70c3c05abc50543492168694c5
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Feb 11 17:53:41 2020 -0500

    css style: Use a linear sweep to compute values
    
    We can again take advantage of the lookup values
    being sorted, and only iterate through them once
    to find all the values for a given group.

 gtk/gtkcssstaticstyle.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index e1db1a3858..8ccc1fe9f0 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -199,19 +199,34 @@ gtk_css_ ## NAME ## _values_new_compute (GtkCssStaticStyle *sstyle, \
                                          GtkCssLookup *lookup) \
 { \
   GtkCssStyle *style = (GtkCssStyle *)sstyle; \
-  int i; \
+  int i, j; \
+  int n; \
 \
   style->NAME = (GtkCss ## TYPE ## Values *)gtk_css_values_new (GTK_CSS_ ## ENUM ## _VALUES); \
 \
+  n = lookup->values ? lookup->values->len : 0; \
+  j = 0; \
   for (i = 0; i < G_N_ELEMENTS (NAME ## _props); i++) \
     { \
       guint id = NAME ## _props[i]; \
-      GtkCssLookupValue *value = gtk_css_lookup_get (lookup, id); \
+      GtkCssValue *value = NULL; \
+      for (; j < n; j++) \
+        { \
+          GtkCssLookupValue *v = g_ptr_array_index (lookup->values, j); \
+          if (v->id > id) \
+            break; \
+          if (v->id == id) \
+            { \
+              value = v->value; \
+              break; \
+            } \
+        } \
+\
       gtk_css_static_style_compute_value (sstyle, \
                                           provider, \
                                           parent_style, \
                                           id, \
-                                          value ? value->value : NULL); \
+                                          value); \
     } \
 } \
 static GtkBitmask * gtk_css_ ## NAME ## _values_mask; \


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