LibWeb: Cache "has size containment" flag in Layout::Box

Allows us to avoid DOM node lookup whenever we need to query natural
size of a box during layout.

Makes 3-4% of `Box::preferred_aspect_ratio()` go away from profiles on
www.nyan.cat
This commit is contained in:
Aliaksandr Kalenik 2025-03-26 16:48:59 +00:00 committed by Jelle Raaijmakers
commit 7cae4fadbc
Notes: github-actions[bot] 2025-03-26 17:53:01 +00:00
3 changed files with 11 additions and 6 deletions

View file

@ -1321,6 +1321,9 @@ void Document::update_layout(UpdateLayoutReason reason)
}
m_layout_root->for_each_in_inclusive_subtree_of_type<Layout::Box>([&](auto& child) {
if (auto dom_node = child.dom_node(); dom_node && dom_node->is_element()) {
child.set_has_size_containment(as<Element>(*dom_node).has_size_containment());
}
bool needs_layout_update = child.dom_node() && child.dom_node()->needs_layout_update();
if (needs_layout_update || child.is_anonymous()) {
child.reset_cached_intrinsic_sizes();