[gtk/wip/baedert/for-master: 55/62] cssselector: Use a GtkArray to count exact matches
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master: 55/62] cssselector: Use a GtkArray to count exact matches
- Date: Sat, 2 May 2020 05:45:50 +0000 (UTC)
commit cf33475bd79a3db4d157256f822b6c76400661c4
Author: Timm Bäder <mail baedert org>
Date: Wed Apr 29 10:01:25 2020 +0200
cssselector: Use a GtkArray to count exact matches
The list here is at most 3 elements long in my tests.
gtk/gtkarrayimplprivate.h | 9 +++++++++
gtk/gtkcssselector.c | 21 +++++++++++----------
2 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkarrayimplprivate.h b/gtk/gtkarrayimplprivate.h
index 0027aa5b3e8..cfc497e1abd 100644
--- a/gtk/gtkarrayimplprivate.h
+++ b/gtk/gtkarrayimplprivate.h
@@ -96,5 +96,14 @@ gtk_array_free (GtkArray *self,
g_ptr_array_free (self->ptr_array, TRUE);
}
+static inline void **
+gtk_array_get_data (GtkArray *self)
+{
+ if (G_LIKELY (!self->ptr_array))
+ return self->stack_space;
+
+ return self->ptr_array->pdata;
+}
+
#endif
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 1c1d0c40467..5c1572e038c 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -24,6 +24,7 @@
#include "gtkcssprovider.h"
#include "gtkstylecontextprivate.h"
+#include "gtkarrayimplprivate.h"
#include <errno.h>
#if defined(_MSC_VER) && _MSC_VER >= 1500
@@ -2119,7 +2120,8 @@ subdivide_infos (GByteArray *array,
GHashTableIter iter;
guint max_count;
gpointer key, value;
- GPtrArray *exact_matches;
+ void *exact_matches_stack[8];
+ GtkArray exact_matches_array;
gint32 res;
guint i;
@@ -2161,7 +2163,7 @@ subdivide_infos (GByteArray *array,
matched_infos = g_alloca (sizeof (GtkCssSelectorRuleSetInfo *) * n_infos);
remaining_infos = g_alloca (sizeof (GtkCssSelectorRuleSetInfo *) * n_infos);
- exact_matches = NULL;
+ gtk_array_init (&exact_matches_array, (void**)exact_matches_stack, 8);
for (i = 0; i < n_infos; i++)
{
GtkCssSelectorRuleSetInfo *info = infos[i];
@@ -2172,9 +2174,7 @@ subdivide_infos (GByteArray *array,
if (info->current_selector == NULL)
{
/* Matches current node */
- if (exact_matches == NULL)
- exact_matches = g_ptr_array_new ();
- g_ptr_array_add (exact_matches, info->match);
+ gtk_array_add (&exact_matches_array, info->match);
if (info->selector_match != NULL)
*info->selector_match = GUINT_TO_POINTER (tree_offset);
}
@@ -2191,13 +2191,14 @@ subdivide_infos (GByteArray *array,
}
}
- if (exact_matches)
+ if (exact_matches_array.len > 0)
{
- g_ptr_array_add (exact_matches, NULL); /* Null terminate */
+ gtk_array_add (&exact_matches_array, NULL); /* Null terminate */
res = array->len;
- g_byte_array_append (array, (guint8 *)exact_matches->pdata,
- exact_matches->len * sizeof (gpointer));
- g_ptr_array_free (exact_matches, TRUE);
+ 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);
}
else
res = GTK_CSS_SELECTOR_TREE_EMPTY_OFFSET;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]