mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:27:34 +00:00
LibWeb: Make StackingContext sorting a lot faster
Stacking contexts are sorted after building a tree of them. They are sorted by z-index first, DOM tree order second. Sorting was previously *very* slow on pages with many stacking contexts. That was because the sort() function used Node::is_before() in the quick_sort comparator to see if one StackingContext was before another. is_before() does tree traversal and can take quite a long time per call. This patch avoids all that by letting StackingContext know its index among all StackingContexts within the same document in tree order. There's a noticeable snappiness increase on the CSS-FLEXBOX-1 spec page, for instance. :^)
This commit is contained in:
parent
500b7b08d6
commit
d6c3cbd958
3 changed files with 8 additions and 5 deletions
|
@ -33,8 +33,9 @@ void Viewport::build_stacking_context_tree_if_needed()
|
|||
|
||||
void Viewport::build_stacking_context_tree()
|
||||
{
|
||||
const_cast<Painting::PaintableBox*>(paintable_box())->set_stacking_context(make<Painting::StackingContext>(*this, nullptr));
|
||||
const_cast<Painting::PaintableBox*>(paintable_box())->set_stacking_context(make<Painting::StackingContext>(*this, nullptr, 0));
|
||||
|
||||
size_t index_in_tree_order = 1;
|
||||
for_each_in_subtree_of_type<Box>([&](Box& box) {
|
||||
if (!box.paintable_box())
|
||||
return IterationDecision::Continue;
|
||||
|
@ -45,7 +46,7 @@ void Viewport::build_stacking_context_tree()
|
|||
}
|
||||
auto* parent_context = const_cast<Painting::PaintableBox*>(box.paintable_box())->enclosing_stacking_context();
|
||||
VERIFY(parent_context);
|
||||
const_cast<Painting::PaintableBox*>(box.paintable_box())->set_stacking_context(make<Painting::StackingContext>(box, parent_context));
|
||||
const_cast<Painting::PaintableBox*>(box.paintable_box())->set_stacking_context(make<Painting::StackingContext>(box, parent_context, index_in_tree_order++));
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue