[gtk/wip/otte/vector: 5/13] cssselector: Use GtkVector



commit 316e1cfb8c3601f4d66e1784187b5c3022177171
Author: Benjamin Otte <otte redhat com>
Date:   Thu Jul 2 18:30:55 2020 +0200

    cssselector: Use GtkVector

 gtk/gtkcssprovider.c        | 28 +++++++++++++---------------
 gtk/gtkcssselector.c        | 37 +++++++++++++++++--------------------
 gtk/gtkcssselectorprivate.h | 11 ++++++++---
 3 files changed, 38 insertions(+), 38 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index ff9df272de..cf711c7bf0 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -391,9 +391,9 @@ gtk_css_provider_init (GtkCssProvider *css_provider)
 }
 
 static void
-verify_tree_match_results (GtkCssProvider *provider,
-                           GtkCssNode     *node,
-                           GtkArray       *tree_rules)
+verify_tree_match_results (GtkCssProvider        *provider,
+                           GtkCssNode            *node,
+                           GtkCssSelectorMatches *tree_rules)
 {
 #ifdef VERIFY_TREE
   GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
@@ -407,9 +407,9 @@ verify_tree_match_results (GtkCssProvider *provider,
 
       ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
 
-      for (j = 0; j < tree_rules->len; j++)
+      for (j = 0; j < gtk_css_selector_matches_get_size (tree_rules); j++)
        {
-         if (ruleset == gtk_array_index (tree_rules, j))
+         if (ruleset == gtk_css_selector_matches_get (tree_rules, j))
            {
              found = TRUE;
              break;
@@ -459,22 +459,21 @@ gtk_css_style_provider_lookup (GtkStyleProvider             *provider,
   GtkCssRuleset *ruleset;
   guint j;
   int i;
-  GtkArray tree_rules_array;
-  GtkCssRuleset *rules_stack[32];
+  GtkCssSelectorMatches tree_rules;
 
   if (_gtk_css_selector_tree_is_empty (priv->tree))
     return;
 
-  gtk_array_init (&tree_rules_array, (void**)rules_stack, 32);
-  _gtk_css_selector_tree_match_all (priv->tree, filter, node, &tree_rules_array);
+  gtk_css_selector_matches_init (&tree_rules);
+  _gtk_css_selector_tree_match_all (priv->tree, filter, node, &tree_rules);
 
-  if (tree_rules_array.len > 0)
+  if (!gtk_css_selector_matches_is_empty (&tree_rules))
     {
-      verify_tree_match_results (css_provider, node, &tree_rules_array);
+      verify_tree_match_results (css_provider, node, &tree_rules);
 
-      for (i = tree_rules_array.len - 1; i >= 0; i--)
+      for (i = gtk_css_selector_matches_get_size (&tree_rules) - 1; i >= 0; i--)
         {
-          ruleset = gtk_array_index (&tree_rules_array, i);
+          ruleset = gtk_css_selector_matches_get (&tree_rules, i);
 
           if (ruleset->styles == NULL)
             continue;
@@ -493,9 +492,8 @@ gtk_css_style_provider_lookup (GtkStyleProvider             *provider,
                                    ruleset->styles[j].value);
             }
         }
-
-      gtk_array_free (&tree_rules_array, NULL);
     }
+  gtk_css_selector_matches_clear (&tree_rules);
 
   if (change)
     *change = gtk_css_selector_tree_get_change_all (priv->tree, filter, node);
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 75c64898c5..7c7c0f8740 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -24,7 +24,6 @@
 
 #include "gtkcssprovider.h"
 #include "gtkstylecontextprivate.h"
-#include "gtkarrayimplprivate.h"
 
 #include <errno.h>
 #if defined(_MSC_VER) && _MSC_VER >= 1500
@@ -152,14 +151,14 @@ gtk_css_selector_tree_get_matches (const GtkCssSelectorTree *tree)
 }
 
 static void
-gtk_array_insert_sorted (GtkArray *array,
-                         gpointer  data)
+gtk_css_selector_matches_insert_sorted (GtkCssSelectorMatches *matches,
+                                        gpointer               data)
 {
   guint i;
 
-  for (i = 0; i < array->len; i++)
+  for (i = 0; i < gtk_css_selector_matches_get_size (matches); i++)
     {
-      gpointer elem = gtk_array_index (array, i);
+      gpointer elem = gtk_css_selector_matches_get (matches, i);
 
       if (data == elem)
         return;
@@ -168,7 +167,7 @@ gtk_array_insert_sorted (GtkArray *array,
         break;
     }
 
-  gtk_array_insert (array, i, data);
+  gtk_css_selector_matches_splice (matches, i, 0, (gpointer[1]) { data }, 1);
 }
 
 static inline gboolean
@@ -1877,7 +1876,7 @@ gtk_css_selector_tree_get_change (const GtkCssSelectorTree     *tree,
 
 static void
 gtk_css_selector_tree_found_match (const GtkCssSelectorTree  *tree,
-                                   GtkArray                  *results)
+                                   GtkCssSelectorMatches     *results)
 {
   int i;
   gpointer *matches;
@@ -1887,7 +1886,7 @@ gtk_css_selector_tree_found_match (const GtkCssSelectorTree  *tree,
     return;
 
   for (i = 0; matches[i] != NULL; i++)
-    gtk_array_insert_sorted (results, matches[i]);
+    gtk_css_selector_matches_insert_sorted (results, matches[i]);
 }
 
 static gboolean
@@ -1895,7 +1894,7 @@ gtk_css_selector_tree_match (const GtkCssSelectorTree      *tree,
                              const GtkCountingBloomFilter  *filter,
                              gboolean                       match_filter,
                              GtkCssNode                    *node,
-                             GtkArray                      *results)
+                             GtkCssSelectorMatches         *results)
 {
   const GtkCssSelectorTree *prev;
   GtkCssNode *child;
@@ -1932,7 +1931,7 @@ void
 _gtk_css_selector_tree_match_all (const GtkCssSelectorTree     *tree,
                                   const GtkCountingBloomFilter *filter,
                                   GtkCssNode                   *node,
-                                  GtkArray                     *out_tree_rules)
+                                  GtkCssSelectorMatches        *out_tree_rules)
 {
   const GtkCssSelectorTree *iter;
 
@@ -2117,8 +2116,7 @@ subdivide_infos (GByteArray                 *array,
   GHashTableIter iter;
   guint max_count;
   gpointer key, value;
-  void *exact_matches_stack[8];
-  GtkArray exact_matches_array;
+  GtkCssSelectorMatches exact_matches;
   gint32 res;
   guint i;
 
@@ -2160,7 +2158,7 @@ subdivide_infos (GByteArray                 *array,
   matched_infos = g_alloca (sizeof (GtkCssSelectorRuleSetInfo *) * n_infos);
   remaining_infos = g_alloca (sizeof (GtkCssSelectorRuleSetInfo *) * n_infos);
 
-  gtk_array_init (&exact_matches_array, (void**)exact_matches_stack, 8);
+  gtk_css_selector_matches_init (&exact_matches);
   for (i = 0; i < n_infos; i++)
     {
       GtkCssSelectorRuleSetInfo *info = infos[i];
@@ -2171,7 +2169,7 @@ subdivide_infos (GByteArray                 *array,
          if (info->current_selector == NULL)
            {
              /* Matches current node */
-              gtk_array_add (&exact_matches_array, info->match);
+              gtk_css_selector_matches_append (&exact_matches, info->match);
              if (info->selector_match != NULL)
                *info->selector_match = GUINT_TO_POINTER (tree_offset);
            }
@@ -2188,17 +2186,16 @@ subdivide_infos (GByteArray                 *array,
        }
     }
 
-  if (exact_matches_array.len > 0)
+  if (!gtk_css_selector_matches_is_empty (&exact_matches))
     {
-      gtk_array_add (&exact_matches_array, NULL); /* Null terminate */
+      gtk_css_selector_matches_append (&exact_matches, NULL); /* Null terminate */
       res = array->len;
-      g_byte_array_append (array, (guint8 *)gtk_array_get_data (&exact_matches_array),
-                           exact_matches_array.len * sizeof (gpointer));
-
-      gtk_array_free (&exact_matches_array, NULL);
+      g_byte_array_append (array, (guint8 *) gtk_css_selector_matches_get_data (&exact_matches),
+                           gtk_css_selector_matches_get_size (&exact_matches) * sizeof (gpointer));
     }
   else
     res = GTK_CSS_SELECTOR_TREE_EMPTY_OFFSET;
+  gtk_css_selector_matches_clear (&exact_matches);
   get_tree (array, tree_offset)->matches_offset = res;
 
   res = subdivide_infos (array, matched_infos, n_matched, tree_offset);
diff --git a/gtk/gtkcssselectorprivate.h b/gtk/gtkcssselectorprivate.h
index f635066435..12c3f38902 100644
--- a/gtk/gtkcssselectorprivate.h
+++ b/gtk/gtkcssselectorprivate.h
@@ -21,7 +21,12 @@
 #include "gtk/gtkcountingbloomfilterprivate.h"
 #include "gtk/gtkcsstypesprivate.h"
 #include "gtk/gtkcssparserprivate.h"
-#include "gtk/gtkarrayimplprivate.h"
+
+#define GTK_VECTOR_ELEMENT_TYPE gpointer
+#define GTK_VECTOR_TYPE_NAME GtkCssSelectorMatches
+#define GTK_VECTOR_NAME gtk_css_selector_matches
+#define GTK_VECTOR_PREALLOC 32
+#include "gtk/gtkvectorimpl.c"
 
 G_BEGIN_DECLS
 
@@ -45,8 +50,8 @@ int               _gtk_css_selector_compare         (const GtkCssSelector   *a,
 void         _gtk_css_selector_tree_free             (GtkCssSelectorTree       *tree);
 void         _gtk_css_selector_tree_match_all        (const GtkCssSelectorTree *tree,
                                                       const GtkCountingBloomFilter *filter,
-                                                      GtkCssNode                   *node,
-                                                      GtkArray                     *out_tree_rules);
+                                                      GtkCssNode               *node,
+                                                      GtkCssSelectorMatches    *out_tree_rules);
 GtkCssChange gtk_css_selector_tree_get_change_all    (const GtkCssSelectorTree *tree,
                                                       const GtkCountingBloomFilter *filter,
                                                      GtkCssNode               *node);


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