mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 17:17:42 +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:
parent
d0312f6208
commit
9b8464f455
4 changed files with 27 additions and 12 deletions
|
@ -642,7 +642,7 @@ void LayoutBlock::place_block_level_non_replaced_element_in_normal_flow(LayoutBl
|
||||||
|
|
||||||
auto* relevant_sibling = block.previous_sibling();
|
auto* relevant_sibling = block.previous_sibling();
|
||||||
while (relevant_sibling != nullptr) {
|
while (relevant_sibling != nullptr) {
|
||||||
if (relevant_sibling->style().position() != CSS::Position::Absolute)
|
if (relevant_sibling->position() != CSS::Position::Absolute)
|
||||||
break;
|
break;
|
||||||
relevant_sibling = relevant_sibling->previous_sibling();
|
relevant_sibling = relevant_sibling->previous_sibling();
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,7 +323,7 @@ bool LayoutBox::establishes_stacking_context() const
|
||||||
return false;
|
return false;
|
||||||
if (node() == document().root())
|
if (node() == document().root())
|
||||||
return true;
|
return true;
|
||||||
auto position = style().position();
|
auto position = this->position();
|
||||||
auto z_index = style().z_index();
|
auto z_index = style().z_index();
|
||||||
if (position == CSS::Position::Absolute || position == CSS::Position::Relative) {
|
if (position == CSS::Position::Absolute || position == CSS::Position::Relative) {
|
||||||
if (z_index.has_value())
|
if (z_index.has_value())
|
||||||
|
|
|
@ -57,7 +57,7 @@ void LayoutNode::layout(LayoutMode layout_mode)
|
||||||
|
|
||||||
bool LayoutNode::can_contain_boxes_with_position_absolute() const
|
bool LayoutNode::can_contain_boxes_with_position_absolute() const
|
||||||
{
|
{
|
||||||
return style().position() != CSS::Position::Static || is_root();
|
return position() != CSS::Position::Static || is_root();
|
||||||
}
|
}
|
||||||
|
|
||||||
const LayoutBlock* LayoutNode::containing_block() const
|
const LayoutBlock* LayoutNode::containing_block() const
|
||||||
|
@ -72,7 +72,7 @@ const LayoutBlock* LayoutNode::containing_block() const
|
||||||
if (is_text())
|
if (is_text())
|
||||||
return nearest_block_ancestor();
|
return nearest_block_ancestor();
|
||||||
|
|
||||||
auto position = style().position();
|
auto position = this->position();
|
||||||
|
|
||||||
if (position == CSS::Position::Absolute) {
|
if (position == CSS::Position::Absolute) {
|
||||||
auto* ancestor = parent();
|
auto* ancestor = parent();
|
||||||
|
@ -199,7 +199,7 @@ bool LayoutNode::is_absolutely_positioned() const
|
||||||
{
|
{
|
||||||
if (!has_style())
|
if (!has_style())
|
||||||
return false;
|
return false;
|
||||||
auto position = style().position();
|
auto position = this->position();
|
||||||
return position == CSS::Position::Absolute || position == CSS::Position::Fixed;
|
return position == CSS::Position::Absolute || position == CSS::Position::Fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,16 @@ bool LayoutNode::is_fixed_position() const
|
||||||
{
|
{
|
||||||
if (!has_style())
|
if (!has_style())
|
||||||
return false;
|
return false;
|
||||||
return style().position() == CSS::Position::Fixed;
|
auto position = this->position();
|
||||||
|
return position == CSS::Position::Fixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
LayoutNodeWithStyle::LayoutNodeWithStyle(const Node* node, NonnullRefPtr<StyleProperties> style)
|
||||||
|
: LayoutNode(node)
|
||||||
|
, m_style(move(style))
|
||||||
|
{
|
||||||
|
m_has_style = true;
|
||||||
|
m_position = m_style->position();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,7 @@ public:
|
||||||
virtual LayoutNode& inline_wrapper() { return *this; }
|
virtual LayoutNode& inline_wrapper() { return *this; }
|
||||||
|
|
||||||
const StyleProperties& style() const;
|
const StyleProperties& style() const;
|
||||||
|
CSS::Position position() const;
|
||||||
|
|
||||||
LayoutNodeWithStyle* parent();
|
LayoutNodeWithStyle* parent();
|
||||||
const LayoutNodeWithStyle* parent() const;
|
const LayoutNodeWithStyle* parent() const;
|
||||||
|
@ -257,16 +258,14 @@ public:
|
||||||
const StyleProperties& style() const { return m_style; }
|
const StyleProperties& style() const { return m_style; }
|
||||||
void set_style(const StyleProperties& style) { m_style = style; }
|
void set_style(const StyleProperties& style) { m_style = style; }
|
||||||
|
|
||||||
|
CSS::Position position() const { return m_position; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit LayoutNodeWithStyle(const Node* node, NonnullRefPtr<StyleProperties> style)
|
explicit LayoutNodeWithStyle(const Node*, NonnullRefPtr<StyleProperties>);
|
||||||
: LayoutNode(node)
|
|
||||||
, m_style(move(style))
|
|
||||||
{
|
|
||||||
m_has_style = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NonnullRefPtr<StyleProperties> m_style;
|
NonnullRefPtr<StyleProperties> m_style;
|
||||||
|
CSS::Position m_position;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LayoutNodeWithStyleAndBoxModelMetrics : public LayoutNodeWithStyle {
|
class LayoutNodeWithStyleAndBoxModelMetrics : public LayoutNodeWithStyle {
|
||||||
|
@ -291,6 +290,13 @@ inline const StyleProperties& LayoutNode::style() const
|
||||||
return parent()->style();
|
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
|
inline const LayoutNodeWithStyle* LayoutNode::parent() const
|
||||||
{
|
{
|
||||||
return static_cast<const LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent());
|
return static_cast<const LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue