mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 01:27:42 +00:00
LibWeb: Limit style update tree traversal to dirty subtrees
This patch adds a second style dirty bit that tracks whether a DOM node has one or more children with dirty style. This allows the style update to skip over entire subtrees where all nodes are clean.
This commit is contained in:
parent
d1479aef56
commit
6809be436b
3 changed files with 32 additions and 7 deletions
|
@ -400,13 +400,25 @@ void Document::update_layout()
|
|||
}
|
||||
}
|
||||
|
||||
void Document::update_style()
|
||||
static void update_style_recursively(DOM::Node& node)
|
||||
{
|
||||
for_each_in_subtree_of_type<Element>([&](auto& element) {
|
||||
if (element.needs_style_update())
|
||||
element.recompute_style();
|
||||
node.for_each_child([&](auto& child) {
|
||||
if (child.needs_style_update()) {
|
||||
if (is<Element>(child))
|
||||
downcast<Element>(child).recompute_style();
|
||||
child.set_needs_style_update(false);
|
||||
}
|
||||
if (child.child_needs_style_update()) {
|
||||
update_style_recursively(child);
|
||||
child.set_child_needs_style_update(false);
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
void Document::update_style()
|
||||
{
|
||||
update_style_recursively(*this);
|
||||
update_layout();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue