Don't invalidate parent if it didn't change

This looks like a leftover excess invalidation from when the surrounding
code was refactored to not just be called on parent changes but also
when repositioning inside the same parent in commit
507016cafc

Ivan Molodetskikh found this problem in
https://gitlab.gnome.org/GNOME/gtk/-/issues/3334#note_1445873 which
contains a longer analysis of this problem and the performance
reductions it causes.

Related: #3334
This commit is contained in:
Benjamin Otte 2022-05-06 11:50:55 +00:00
parent b74aec3606
commit c29bf115f2

View File

@ -239,7 +239,7 @@ gtk_css_node_dispose (GObject *object)
} }
gtk_css_node_set_invalid (cssnode, FALSE); gtk_css_node_set_invalid (cssnode, FALSE);
g_clear_pointer (&cssnode->cache, gtk_css_node_style_cache_unref); g_clear_pointer (&cssnode->cache, gtk_css_node_style_cache_unref);
G_OBJECT_CLASS (gtk_css_node_parent_class)->dispose (object); G_OBJECT_CLASS (gtk_css_node_parent_class)->dispose (object);
@ -292,7 +292,7 @@ may_use_global_parent_cache (GtkCssNode *node)
{ {
GtkStyleProvider *provider; GtkStyleProvider *provider;
GtkCssNode *parent; GtkCssNode *parent;
parent = gtk_css_node_get_parent (node); parent = gtk_css_node_get_parent (node);
if (parent == NULL) if (parent == NULL)
return FALSE; return FALSE;
@ -700,10 +700,10 @@ gtk_css_node_invalidate_style (GtkCssNode *cssnode)
cssnode->style_is_invalid = TRUE; cssnode->style_is_invalid = TRUE;
gtk_css_node_set_invalid (cssnode, TRUE); gtk_css_node_set_invalid (cssnode, TRUE);
if (cssnode->first_child) if (cssnode->first_child)
gtk_css_node_invalidate_style (cssnode->first_child); gtk_css_node_invalidate_style (cssnode->first_child);
if (cssnode->next_sibling) if (cssnode->next_sibling)
gtk_css_node_invalidate_style (cssnode->next_sibling); gtk_css_node_invalidate_style (cssnode->next_sibling);
} }
@ -796,7 +796,7 @@ gtk_css_node_reposition (GtkCssNode *node,
gtk_css_node_invalidate_style (node->next_sibling); gtk_css_node_invalidate_style (node->next_sibling);
} }
gtk_css_node_invalidate (node, GTK_CSS_CHANGE_ANY_PARENT gtk_css_node_invalidate (node, (old_parent != new_parent ? GTK_CSS_CHANGE_ANY_PARENT : 0)
| GTK_CSS_CHANGE_ANY_SIBLING | GTK_CSS_CHANGE_ANY_SIBLING
| GTK_CSS_CHANGE_NTH_CHILD | GTK_CSS_CHANGE_NTH_CHILD
| (node->previous_sibling ? 0 : GTK_CSS_CHANGE_FIRST_CHILD) | (node->previous_sibling ? 0 : GTK_CSS_CHANGE_FIRST_CHILD)
@ -842,7 +842,7 @@ gtk_css_node_insert_before (GtkCssNode *parent,
g_return_if_fail (next_sibling == NULL || next_sibling->parent == parent); g_return_if_fail (next_sibling == NULL || next_sibling->parent == parent);
g_return_if_fail (cssnode != next_sibling); g_return_if_fail (cssnode != next_sibling);
if (cssnode->next_sibling == next_sibling && if (cssnode->next_sibling == next_sibling &&
cssnode->parent == parent) cssnode->parent == parent)
return; return;
@ -1067,7 +1067,7 @@ gtk_css_node_set_visible (GtkCssNode *cssnode,
} }
} }
} }
if (cssnode->previous_sibling) if (cssnode->previous_sibling)
{ {
if (gtk_css_node_is_last_child (cssnode)) if (gtk_css_node_is_last_child (cssnode))
@ -1424,7 +1424,7 @@ gtk_css_node_print (GtkCssNode *cssnode,
change = gtk_css_static_style_get_change (gtk_css_style_get_static_style (style)); change = gtk_css_static_style_get_change (gtk_css_style_get_static_style (style));
g_string_append (string, " "); g_string_append (string, " ");
gtk_css_change_print (change, string); gtk_css_change_print (change, string);
} }
g_string_append_c (string, '\n'); g_string_append_c (string, '\n');