mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:47:35 +00:00
LibWeb: Skip assigning slottables for non-shadow roots
For example, on https://html.spec.whatwg.org, there are hundreds of thousands of nodes. This method is invoked as each node is inserted. Traversing the entire tree each time takes a prohibitively long time, so let's bail early when we know the operation is a no-op.
This commit is contained in:
parent
f3e14d7f64
commit
cdbde1765a
1 changed files with 6 additions and 0 deletions
|
@ -176,6 +176,12 @@ void assign_slottables(JS::NonnullGCPtr<HTML::HTMLSlotElement> slot)
|
||||||
// https://dom.spec.whatwg.org/#assign-slotables-for-a-tree
|
// https://dom.spec.whatwg.org/#assign-slotables-for-a-tree
|
||||||
void assign_slottables_for_a_tree(JS::NonnullGCPtr<Node> root)
|
void assign_slottables_for_a_tree(JS::NonnullGCPtr<Node> root)
|
||||||
{
|
{
|
||||||
|
// AD-HOC: This method iterates over the root's entire subtree. That iteration does nothing if the root is not a
|
||||||
|
// shadow root (see `find_slottables`). This iteration can be very expensive as the HTML parser inserts
|
||||||
|
// nodes, especially on sites with many elements. So we skip it if we know it's going to be a no-op anyways.
|
||||||
|
if (!root->is_shadow_root())
|
||||||
|
return;
|
||||||
|
|
||||||
// To assign slottables for a tree, given a node root, run assign slottables for each slot slot in root’s inclusive
|
// To assign slottables for a tree, given a node root, run assign slottables for each slot slot in root’s inclusive
|
||||||
// descendants, in tree order.
|
// descendants, in tree order.
|
||||||
root->for_each_in_inclusive_subtree_of_type<HTML::HTMLSlotElement>([](auto& slot) {
|
root->for_each_in_inclusive_subtree_of_type<HTML::HTMLSlotElement>([](auto& slot) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue