LibWeb: Avoid iterating in children_changed unless necessary

Previously when one child of an element changed we would iterate over
every child to check whether they needed to be invalidated because they
relied on tree counting functions.

We now skip this in most cases by only doing it when at least one child
relies on tree counting functions.
This commit is contained in:
Callum Law 2025-10-21 13:39:42 +13:00 committed by Jelle Raaijmakers
parent 6afd39b16a
commit a4184fda1f
Notes: github-actions[bot] 2025-10-21 23:02:12 +00:00
2 changed files with 20 additions and 9 deletions

View file

@ -1395,14 +1395,15 @@ void Element::children_changed(ChildrenChangedMetadata const* metadata)
{
Node::children_changed(metadata);
set_needs_style_update(true);
for_each_child([&](DOM::Node& child) {
if (auto* element = as_if<DOM::Element>(child); element && element->style_uses_tree_counting_function()) {
element->set_needs_style_update(true);
set_child_needs_style_update(true);
}
return IterationDecision::Continue;
});
if (child_style_uses_tree_counting_function()) {
for_each_child_of_type<Element>([&](Element& element) {
element.set_needs_style_update(true);
set_child_needs_style_update(true);
return IterationDecision::Continue;
});
}
}
void Element::set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::PseudoElement pseudo_element, GC::Ptr<Layout::NodeWithStyle> pseudo_element_node)