mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibWeb: Sort stacking context tree once, after fully building it
Instead of calling quick_sort() every time a StackingContext child is added to a parent, we now do a single pass of sorting work after the full StackingContext tree has been built. Before this change, the quick_sort() was ~13.5% of the profile while hovering links on GitHub in the Browser. After the change, it's down to ~0.6%. Pretty good! :^)
This commit is contained in:
parent
0dfb9714fe
commit
f5c2e87965
3 changed files with 18 additions and 10 deletions
|
@ -26,18 +26,22 @@ StackingContext::StackingContext(Layout::Box& box, StackingContext* parent)
|
|||
, m_parent(parent)
|
||||
{
|
||||
VERIFY(m_parent != this);
|
||||
if (m_parent) {
|
||||
if (m_parent)
|
||||
m_parent->m_children.append(this);
|
||||
}
|
||||
|
||||
// FIXME: Don't sort on every append..
|
||||
quick_sort(m_parent->m_children, [](auto& a, auto& b) {
|
||||
auto a_z_index = a->m_box.computed_values().z_index().value_or(0);
|
||||
auto b_z_index = b->m_box.computed_values().z_index().value_or(0);
|
||||
if (a_z_index == b_z_index)
|
||||
return a->m_box.is_before(b->m_box);
|
||||
return a_z_index < b_z_index;
|
||||
});
|
||||
}
|
||||
void StackingContext::sort()
|
||||
{
|
||||
quick_sort(m_children, [](auto& a, auto& b) {
|
||||
auto a_z_index = a->m_box.computed_values().z_index().value_or(0);
|
||||
auto b_z_index = b->m_box.computed_values().z_index().value_or(0);
|
||||
if (a_z_index == b_z_index)
|
||||
return a->m_box.is_before(b->m_box);
|
||||
return a_z_index < b_z_index;
|
||||
});
|
||||
|
||||
for (auto* child : m_children)
|
||||
child->sort();
|
||||
}
|
||||
|
||||
void StackingContext::paint_descendants(PaintContext& context, Layout::Node& box, StackingContextPaintPhase phase) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue