css: Avoid computing change too often
Most of the time when styles need to be recreated, the name and classes of the css node haven't changed. In this case, the change value will not either, since we are computing change under the assumption that name and classes are unchanged, so there is no need to recompute the change.
This commit is contained in:
@@ -349,12 +349,14 @@ store_in_global_parent_cache (GtkCssNode *node,
|
||||
}
|
||||
|
||||
static GtkCssStyle *
|
||||
gtk_css_node_create_style (GtkCssNode *cssnode)
|
||||
gtk_css_node_create_style (GtkCssNode *cssnode,
|
||||
GtkCssChange change)
|
||||
{
|
||||
const GtkCssNodeDeclaration *decl;
|
||||
GtkCssMatcher matcher;
|
||||
GtkCssStyle *parent;
|
||||
GtkCssStyle *style;
|
||||
gboolean compute_change;
|
||||
|
||||
decl = gtk_css_node_get_declaration (cssnode);
|
||||
|
||||
@@ -364,14 +366,24 @@ gtk_css_node_create_style (GtkCssNode *cssnode)
|
||||
|
||||
parent = cssnode->parent ? cssnode->parent->style : NULL;
|
||||
|
||||
compute_change = change & (GTK_CSS_CHANGE_ID | GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE);
|
||||
|
||||
if (gtk_css_node_init_matcher (cssnode, &matcher))
|
||||
style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
|
||||
&matcher,
|
||||
parent);
|
||||
parent,
|
||||
compute_change);
|
||||
else
|
||||
style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
|
||||
NULL,
|
||||
parent);
|
||||
parent,
|
||||
compute_change);
|
||||
|
||||
if (!compute_change)
|
||||
{
|
||||
GtkCssStyle *old_style = gtk_css_style_get_static_style (cssnode->style);
|
||||
((GtkCssStaticStyle *)style)->change = ((GtkCssStaticStyle *)old_style)->change;
|
||||
}
|
||||
|
||||
store_in_global_parent_cache (cssnode, decl, style);
|
||||
|
||||
@@ -411,7 +423,7 @@ gtk_css_node_real_update_style (GtkCssNode *cssnode,
|
||||
static_style = gtk_css_style_get_static_style (style);
|
||||
|
||||
if (gtk_css_style_needs_recreation (static_style, change))
|
||||
new_static_style = gtk_css_node_create_style (cssnode);
|
||||
new_static_style = gtk_css_node_create_style (cssnode, change);
|
||||
else
|
||||
new_static_style = g_object_ref (static_style);
|
||||
|
||||
|
||||
@@ -158,7 +158,8 @@ gtk_css_static_style_get_default (void)
|
||||
settings = gtk_settings_get_default ();
|
||||
default_style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER (settings),
|
||||
NULL,
|
||||
NULL);
|
||||
NULL,
|
||||
TRUE);
|
||||
g_object_set_data_full (G_OBJECT (settings), I_("gtk-default-style"),
|
||||
default_style, clear_default_style);
|
||||
}
|
||||
@@ -169,7 +170,8 @@ gtk_css_static_style_get_default (void)
|
||||
GtkCssStyle *
|
||||
gtk_css_static_style_new_compute (GtkStyleProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssStyle *parent)
|
||||
GtkCssStyle *parent,
|
||||
gboolean compute_change)
|
||||
{
|
||||
GtkCssStaticStyle *result;
|
||||
GtkCssLookup lookup;
|
||||
@@ -181,7 +183,7 @@ gtk_css_static_style_new_compute (GtkStyleProvider *provider,
|
||||
gtk_style_provider_lookup (provider,
|
||||
matcher,
|
||||
&lookup,
|
||||
&change);
|
||||
compute_change ? &change : NULL);
|
||||
|
||||
result = g_object_new (GTK_TYPE_CSS_STATIC_STYLE, NULL);
|
||||
|
||||
|
||||
@@ -55,7 +55,8 @@ GType gtk_css_static_style_get_type (void) G_GNUC_CO
|
||||
GtkCssStyle * gtk_css_static_style_get_default (void);
|
||||
GtkCssStyle * gtk_css_static_style_new_compute (GtkStyleProvider *provider,
|
||||
const GtkCssMatcher *matcher,
|
||||
GtkCssStyle *parent);
|
||||
GtkCssStyle *parent,
|
||||
gboolean compute_change);
|
||||
|
||||
void gtk_css_static_style_compute_value (GtkCssStaticStyle *style,
|
||||
GtkStyleProvider *provider,
|
||||
|
||||
Reference in New Issue
Block a user