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

@ -33,9 +33,8 @@ Optional<CSSPixels> Box::natural_width() const
// https://drafts.csswg.org/css-contain-2/#containment-size
// Replaced elements must be treated as having a natural width and height of 0 and no natural aspect
// ratio.
if (dom_node() && dom_node()->is_element() && as<DOM::Element>(dom_node())->has_size_containment())
if (m_has_size_containment)
return 0;
return m_natural_width;
}
Optional<CSSPixels> Box::natural_height() const
@ -43,9 +42,8 @@ Optional<CSSPixels> Box::natural_height() const
// https://drafts.csswg.org/css-contain-2/#containment-size
// Replaced elements must be treated as having a natural width and height of 0 and no natural aspect
// ratio.
if (dom_node() && dom_node()->is_element() && as<DOM::Element>(dom_node())->has_size_containment())
if (m_has_size_containment)
return 0;
return m_natural_height;
}
Optional<CSSPixelFraction> Box::natural_aspect_ratio() const
@ -53,9 +51,8 @@ Optional<CSSPixelFraction> Box::natural_aspect_ratio() const
// https://drafts.csswg.org/css-contain-2/#containment-size
// Replaced elements must be treated as having a natural width and height of 0 and no natural aspect
// ratio.
if (dom_node() && dom_node()->is_element() && as<DOM::Element>(dom_node())->has_size_containment())
if (m_has_size_containment)
return {};
return m_natural_aspect_ratio;
}