[gtk/css-lookup-caching: 86/96] css provider: Keep rulesets sorted



commit d342ca85119b5547fa252f32b67ae61ad3c38612
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Feb 11 16:58:16 2020 -0500

    css provider: Keep rulesets sorted
    
    Keep each ruleset sorted by property id. This
    will let us be faster when adding the rules to
    a lookup later on.

 gtk/gtkcssprovider.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 235e8f32eb..95df38ecff 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -277,6 +277,8 @@ gtk_css_ruleset_add (GtkCssRuleset       *ruleset,
 
   for (i = 0; i < ruleset->n_styles; i++)
     {
+      if (ruleset->styles[i].id > id)
+        break;
       if (ruleset->styles[i].id == id)
         {
           _gtk_css_value_unref (ruleset->styles[i].value);
@@ -286,10 +288,15 @@ gtk_css_ruleset_add (GtkCssRuleset       *ruleset,
           break;
         }
     }
-  if (i == ruleset->n_styles)
+  if (i == ruleset->n_styles || ruleset->styles[i].id != id)
     {
+      ruleset->styles = g_realloc (ruleset->styles, (ruleset->n_styles + 1) * sizeof (PropertyValue));
+
+      if (i < ruleset->n_styles)
+        memmove (&ruleset->styles[i + 1], &ruleset->styles[i], (ruleset->n_styles - i) * sizeof 
(PropertyValue));
+
       ruleset->n_styles++;
-      ruleset->styles = g_realloc (ruleset->styles, ruleset->n_styles * sizeof (PropertyValue));
+
       ruleset->styles[i].value = NULL;
       ruleset->styles[i].id = id;
     }


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