[gtk/css-lookup-caching] css provider: Keep rulesets sorted
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/css-lookup-caching] css provider: Keep rulesets sorted
- Date: Tue, 11 Feb 2020 22:55:25 +0000 (UTC)
commit 6ace144531117ea6f3d0c4de33ee9a145c7acff0
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 ceea9057f5..6601d6564b 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]