forked from AuroraMiddleware/gtk
cssprovider: Pass a GtkArray around when matching
We just use the resulting GPtrArray to set the values on a GtkCssLookup and it had mostly a size of 1, in extremes a size of 11.
This commit is contained in:
parent
8b4d84981e
commit
cdb4d71125
@ -30,8 +30,8 @@ gtk_array_init (GtkArray *self,
|
||||
}
|
||||
|
||||
static inline void *
|
||||
gtk_array_index (GtkArray *self,
|
||||
guint index)
|
||||
gtk_array_index (const GtkArray *self,
|
||||
guint index)
|
||||
{
|
||||
g_assert (index < self->len);
|
||||
|
||||
@ -68,6 +68,31 @@ gtk_array_add (GtkArray *self,
|
||||
self->len++; /* We still count self->len */
|
||||
}
|
||||
|
||||
static inline void
|
||||
gtk_array_insert (GtkArray *self,
|
||||
guint index,
|
||||
void *element)
|
||||
{
|
||||
if (index >= self->len)
|
||||
{
|
||||
gtk_array_add (self, element);
|
||||
return;
|
||||
}
|
||||
|
||||
if (G_LIKELY (self->len < self->reserved_size))
|
||||
{
|
||||
memmove (self->stack_space + index + 1, self->stack_space + index,
|
||||
sizeof (void *) * (self->len - index));
|
||||
self->stack_space[index] = element;
|
||||
self->len++;
|
||||
return;
|
||||
}
|
||||
|
||||
g_assert (self->ptr_array);
|
||||
g_ptr_array_insert (self->ptr_array, index, element);
|
||||
self->len++;
|
||||
}
|
||||
|
||||
static inline void
|
||||
gtk_array_free (GtkArray *self,
|
||||
GDestroyNotify element_free_func)
|
||||
|
@ -391,8 +391,8 @@ gtk_css_provider_init (GtkCssProvider *css_provider)
|
||||
|
||||
static void
|
||||
verify_tree_match_results (GtkCssProvider *provider,
|
||||
GtkCssNode *node,
|
||||
GPtrArray *tree_rules)
|
||||
GtkCssNode *node,
|
||||
GtkArray *tree_rules)
|
||||
{
|
||||
#ifdef VERIFY_TREE
|
||||
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
|
||||
@ -408,7 +408,7 @@ verify_tree_match_results (GtkCssProvider *provider,
|
||||
|
||||
for (j = 0; j < tree_rules->len; j++)
|
||||
{
|
||||
if (ruleset == tree_rules->pdata[j])
|
||||
if (ruleset == gtk_array_index (tree_rules, j))
|
||||
{
|
||||
found = TRUE;
|
||||
break;
|
||||
@ -458,19 +458,22 @@ gtk_css_style_provider_lookup (GtkStyleProvider *provider,
|
||||
GtkCssRuleset *ruleset;
|
||||
guint j;
|
||||
int i;
|
||||
GPtrArray *tree_rules;
|
||||
GtkArray tree_rules_array;
|
||||
GtkCssRuleset *rules_stack[32];
|
||||
|
||||
if (_gtk_css_selector_tree_is_empty (priv->tree))
|
||||
return;
|
||||
|
||||
tree_rules = _gtk_css_selector_tree_match_all (priv->tree, filter, node);
|
||||
if (tree_rules)
|
||||
{
|
||||
verify_tree_match_results (css_provider, node, tree_rules);
|
||||
gtk_array_init (&tree_rules_array, (void**)rules_stack, 32);
|
||||
_gtk_css_selector_tree_match_all (priv->tree, filter, node, &tree_rules_array);
|
||||
|
||||
for (i = tree_rules->len - 1; i >= 0; i--)
|
||||
if (tree_rules_array.len > 0)
|
||||
{
|
||||
verify_tree_match_results (css_provider, node, &tree_rules_array);
|
||||
|
||||
for (i = tree_rules_array.len - 1; i >= 0; i--)
|
||||
{
|
||||
ruleset = tree_rules->pdata[i];
|
||||
ruleset = gtk_array_index (&tree_rules_array, i);
|
||||
|
||||
if (ruleset->styles == NULL)
|
||||
continue;
|
||||
@ -490,7 +493,7 @@ gtk_css_style_provider_lookup (GtkStyleProvider *provider,
|
||||
}
|
||||
}
|
||||
|
||||
g_ptr_array_free (tree_rules, TRUE);
|
||||
gtk_array_free (&tree_rules_array, NULL);
|
||||
}
|
||||
|
||||
if (change)
|
||||
|
@ -152,21 +152,23 @@ gtk_css_selector_tree_get_matches (const GtkCssSelectorTree *tree)
|
||||
}
|
||||
|
||||
static void
|
||||
g_ptr_array_insert_sorted (GPtrArray *array,
|
||||
gpointer data)
|
||||
gtk_array_insert_sorted (GtkArray *array,
|
||||
gpointer data)
|
||||
{
|
||||
gint i;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < array->len; i++)
|
||||
{
|
||||
if (data == array->pdata[i])
|
||||
gpointer elem = gtk_array_index (array, i);
|
||||
|
||||
if (data == elem)
|
||||
return;
|
||||
|
||||
if (data < array->pdata[i])
|
||||
if (data < elem)
|
||||
break;
|
||||
}
|
||||
|
||||
g_ptr_array_insert (array, i, data);
|
||||
gtk_array_insert (array, i, data);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
@ -1875,7 +1877,7 @@ gtk_css_selector_tree_get_change (const GtkCssSelectorTree *tree,
|
||||
|
||||
static void
|
||||
gtk_css_selector_tree_found_match (const GtkCssSelectorTree *tree,
|
||||
GPtrArray **results)
|
||||
GtkArray *results)
|
||||
{
|
||||
int i;
|
||||
gpointer *matches;
|
||||
@ -1884,11 +1886,8 @@ gtk_css_selector_tree_found_match (const GtkCssSelectorTree *tree,
|
||||
if (!matches)
|
||||
return;
|
||||
|
||||
if (*results == NULL)
|
||||
*results = g_ptr_array_sized_new (16);
|
||||
|
||||
for (i = 0; matches[i] != NULL; i++)
|
||||
g_ptr_array_insert_sorted (*results, matches[i]);
|
||||
gtk_array_insert_sorted (results, matches[i]);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -1896,7 +1895,7 @@ gtk_css_selector_tree_match (const GtkCssSelectorTree *tree,
|
||||
const GtkCountingBloomFilter *filter,
|
||||
gboolean match_filter,
|
||||
GtkCssNode *node,
|
||||
GPtrArray **results)
|
||||
GtkArray *results)
|
||||
{
|
||||
const GtkCssSelectorTree *prev;
|
||||
GtkCssNode *child;
|
||||
@ -1929,22 +1928,20 @@ gtk_css_selector_tree_match (const GtkCssSelectorTree *tree,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GPtrArray *
|
||||
void
|
||||
_gtk_css_selector_tree_match_all (const GtkCssSelectorTree *tree,
|
||||
const GtkCountingBloomFilter *filter,
|
||||
GtkCssNode *node)
|
||||
GtkCssNode *node,
|
||||
GtkArray *out_tree_rules)
|
||||
{
|
||||
const GtkCssSelectorTree *iter;
|
||||
GPtrArray *results = NULL;
|
||||
|
||||
for (iter = tree;
|
||||
iter != NULL;
|
||||
iter = gtk_css_selector_tree_get_sibling (iter))
|
||||
{
|
||||
gtk_css_selector_tree_match (iter, filter, FALSE, node, &results);
|
||||
gtk_css_selector_tree_match (iter, filter, FALSE, node, out_tree_rules);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "gtk/gtkcountingbloomfilterprivate.h"
|
||||
#include "gtk/gtkcsstypesprivate.h"
|
||||
#include "gtk/gtkcssparserprivate.h"
|
||||
#include "gtk/gtkarrayimplprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -42,9 +43,10 @@ int _gtk_css_selector_compare (const GtkCssSelector *a,
|
||||
const GtkCssSelector *b);
|
||||
|
||||
void _gtk_css_selector_tree_free (GtkCssSelectorTree *tree);
|
||||
GPtrArray * _gtk_css_selector_tree_match_all (const GtkCssSelectorTree *tree,
|
||||
void _gtk_css_selector_tree_match_all (const GtkCssSelectorTree *tree,
|
||||
const GtkCountingBloomFilter *filter,
|
||||
GtkCssNode *node);
|
||||
GtkCssNode *node,
|
||||
GtkArray *out_tree_rules);
|
||||
GtkCssChange gtk_css_selector_tree_get_change_all (const GtkCssSelectorTree *tree,
|
||||
const GtkCountingBloomFilter *filter,
|
||||
GtkCssNode *node);
|
||||
|
Loading…
Reference in New Issue
Block a user