mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb: Avoid subtree iteration when assigning slottables
This change introduces SlotRegistry to track slot elements per shadow root. This allows us to iterate slots directly when assigning slottables for a tree instead of walking an entire subtree.
This commit is contained in:
committed by
Shannon Booth
parent
2017347a77
commit
18b8ba1fd3
Notes:
github-actions[bot]
2026-02-06 10:52:20 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/18b8ba1fd32 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7667 Reviewed-by: https://github.com/gmta Reviewed-by: https://github.com/shannonbooth
@@ -9,6 +9,7 @@
|
||||
#include <LibWeb/Bindings/HTMLSlotElementPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/ShadowRoot.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/HTML/HTMLSlotElement.h>
|
||||
|
||||
@@ -151,6 +152,11 @@ void HTMLSlotElement::attribute_changed(FlyString const& local_name, Optional<St
|
||||
if (value == String {} && !old_value.has_value())
|
||||
return;
|
||||
|
||||
// OPTIMIZATION: Update the slot registry before changing the name.
|
||||
auto* shadow_root = as_if<DOM::ShadowRoot>(root());
|
||||
if (shadow_root)
|
||||
shadow_root->unregister_slot(*this);
|
||||
|
||||
// 4. If value is null or the empty string, then set element’s name to the empty string.
|
||||
if (!value.has_value())
|
||||
set_slot_name({});
|
||||
@@ -158,6 +164,10 @@ void HTMLSlotElement::attribute_changed(FlyString const& local_name, Optional<St
|
||||
else
|
||||
set_slot_name(*value);
|
||||
|
||||
// OPTIMIZATION: Register the slot with its new name.
|
||||
if (shadow_root)
|
||||
shadow_root->register_slot(*this);
|
||||
|
||||
// 6. Run assign slottables for a tree with element’s root.
|
||||
DOM::assign_slottables_for_a_tree(root());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user