1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

LibWeb: Cache the used CSS 'position' value on LayoutNodeWithStyle

This avoids having to query the StyleProperties hash map whenever we
need to know if an element is absolutely positioned. This was extremely
hot in interactive window resize profiles.
This commit is contained in:
Andreas Kling 2020-06-23 23:15:23 +02:00
parent d0312f6208
commit 9b8464f455
4 changed files with 27 additions and 12 deletions

View file

@ -190,6 +190,7 @@ public:
virtual LayoutNode& inline_wrapper() { return *this; }
const StyleProperties& style() const;
CSS::Position position() const;
LayoutNodeWithStyle* parent();
const LayoutNodeWithStyle* parent() const;
@ -257,16 +258,14 @@ public:
const StyleProperties& style() const { return m_style; }
void set_style(const StyleProperties& style) { m_style = style; }
CSS::Position position() const { return m_position; }
protected:
explicit LayoutNodeWithStyle(const Node* node, NonnullRefPtr<StyleProperties> style)
: LayoutNode(node)
, m_style(move(style))
{
m_has_style = true;
}
explicit LayoutNodeWithStyle(const Node*, NonnullRefPtr<StyleProperties>);
private:
NonnullRefPtr<StyleProperties> m_style;
CSS::Position m_position;
};
class LayoutNodeWithStyleAndBoxModelMetrics : public LayoutNodeWithStyle {
@ -291,6 +290,13 @@ inline const StyleProperties& LayoutNode::style() const
return parent()->style();
}
inline CSS::Position LayoutNode::position() const
{
if (m_has_style)
return static_cast<const LayoutNodeWithStyle*>(this)->position();
return parent()->position();
}
inline const LayoutNodeWithStyle* LayoutNode::parent() const
{
return static_cast<const LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent());