From 8111d99183bbe3f10ba4260d319925ae1fc6b96e Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 18 May 2011 05:47:18 +0200 Subject: [PATCH] cssprovider: Cache if rulesets have inheritable style properties This provides a huge speedup as we only need to preprocess style properties when they are indeed inherited. This roughly doubles the performance of the CSS matcher and brings the time taken by gtk_css_provider_get_style() from 19% to 7% in my favorite benchmark. --- gtk/gtkcssprovider.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c index 8dcb09afaa..8659247503 100644 --- a/gtk/gtkcssprovider.c +++ b/gtk/gtkcssprovider.c @@ -745,6 +745,8 @@ struct GtkCssRuleset GtkCssSelector *selector; GHashTable *widget_style; GHashTable *style; + + guint has_inherit :1; }; struct _GtkCssScanner @@ -970,6 +972,7 @@ gtk_css_ruleset_add (GtkCssRuleset *ruleset, NULL, (GDestroyNotify) property_value_free); + ruleset->has_inherit |= gtk_style_param_get_inherit (pspec); g_hash_table_insert (ruleset->style, pspec, value); } @@ -1158,7 +1161,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider, if (ruleset->style == NULL) continue; - if (l < length && _gtk_css_selector_get_state_flags (ruleset->selector)) + if (l < length && (!ruleset->has_inherit || _gtk_css_selector_get_state_flags (ruleset->selector))) continue; if (!gtk_css_ruleset_matches (ruleset, path, l))