Revert "LibWeb: Make "assign slottables for a tree" fast when there are no slots"

This reverts commit adc25af8e2.

This caused images to stop loading on https://reddit.com/ and needs
more investigation.
This commit is contained in:
Andreas Kling 2025-02-04 22:19:25 +01:00
commit b8537f760d
Notes: github-actions[bot] 2025-02-04 21:29:19 +00:00
4 changed files with 11 additions and 49 deletions

View file

@ -64,20 +64,6 @@ public:
virtual void finalize() override;
void increment_slot_count() { ++m_slot_count; }
void decrement_slot_count() { --m_slot_count; }
[[nodiscard]] size_t slot_count() const { return m_slot_count; }
template<typename Callback>
void for_each_slot(Callback callback)
{
if (m_slot_count == 0)
return;
for_each_in_subtree_of_type<HTML::HTMLSlotElement>([&](HTML::HTMLSlotElement& slot) {
return callback(slot);
});
}
protected:
virtual void visit_edges(Cell::Visitor&) override;
@ -106,9 +92,6 @@ private:
GC::Ptr<CSS::StyleSheetList> m_style_sheets;
mutable GC::Ptr<WebIDL::ObservableArray> m_adopted_style_sheets;
// AD-HOC: Number of HTMLSlotElement nodes that are descendants of this ShadowRoot.
size_t m_slot_count { 0 };
};
template<>

View file

@ -74,32 +74,32 @@ GC::Ptr<HTML::HTMLSlotElement> find_a_slot(Slottable const& slottable, OpenFlag
// 5. If shadows slot assignment is "manual", then return the slot in shadows descendants whose manually assigned
// nodes contains slottable, if any; otherwise null.
if (shadow->slot_assignment() == Bindings::SlotAssignmentMode::Manual) {
GC::Ptr<HTML::HTMLSlotElement> found_slot;
GC::Ptr<HTML::HTMLSlotElement> slot;
shadow->for_each_slot([&](auto& slot) {
if (!slot.manually_assigned_nodes().contains_slow(slottable))
shadow->for_each_in_subtree_of_type<HTML::HTMLSlotElement>([&](auto& child) {
if (!child.manually_assigned_nodes().contains_slow(slottable))
return TraversalDecision::Continue;
found_slot = slot;
slot = child;
return TraversalDecision::Break;
});
return found_slot;
return slot;
}
// 6. Return the first slot in tree order in shadows descendants whose name is slottables name, if any; otherwise null.
auto const& slottable_name = slottable.visit([](auto const& node) { return node->slottable_name(); });
GC::Ptr<HTML::HTMLSlotElement> found_slot;
GC::Ptr<HTML::HTMLSlotElement> slot;
shadow->for_each_slot([&](auto& slot) {
if (slot.slot_name() != slottable_name)
shadow->for_each_in_subtree_of_type<HTML::HTMLSlotElement>([&](auto& child) {
if (child.slot_name() != slottable_name)
return TraversalDecision::Continue;
found_slot = slot;
slot = child;
return TraversalDecision::Break;
});
return found_slot;
return slot;
}
// https://dom.spec.whatwg.org/#find-slotables
@ -186,7 +186,7 @@ void assign_slottables_for_a_tree(GC::Ref<Node> root)
// To assign slottables for a tree, given a node root, run assign slottables for each slot slot in roots inclusive
// descendants, in tree order.
static_cast<DOM::ShadowRoot&>(*root).for_each_slot([](auto& slot) {
root->for_each_in_inclusive_subtree_of_type<HTML::HTMLSlotElement>([](auto& slot) {
assign_slottables(slot);
return TraversalDecision::Continue;
});

View file

@ -8,7 +8,6 @@
#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>
@ -148,21 +147,4 @@ void HTMLSlotElement::attribute_changed(FlyString const& local_name, Optional<St
}
}
void HTMLSlotElement::inserted()
{
Base::inserted();
auto& root = this->root();
if (!root.is_shadow_root())
return;
static_cast<DOM::ShadowRoot&>(root).increment_slot_count();
}
void HTMLSlotElement::removed_from(Node* old_parent, Node& old_root)
{
Base::removed_from(old_parent, old_root);
if (!old_root.is_shadow_root())
return;
static_cast<DOM::ShadowRoot&>(old_root).decrement_slot_count();
}
}

View file

@ -45,9 +45,6 @@ private:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(JS::Cell::Visitor&) override;
virtual void inserted() override;
virtual void removed_from(Node* old_parent, Node& old_root) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
// https://html.spec.whatwg.org/multipage/scripting.html#manually-assigned-nodes