mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
LibWeb: Allocate custom element reactions queue on demand
This shrinks most DOM elements by 16 bytes.
This commit is contained in:
parent
ac8bb89f50
commit
7ee47d81ca
Notes:
sideshowbarker
2024-07-17 09:41:18 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7ee47d81ca Pull-request: https://github.com/SerenityOS/serenity/pull/21991
@ -675,12 +675,14 @@ void invoke_custom_element_reactions(Vector<JS::Handle<DOM::Element>>& element_q
|
||||
auto element = element_queue.take_first();
|
||||
|
||||
// 2. Let reactions be element's custom element reaction queue.
|
||||
auto& reactions = element->custom_element_reaction_queue();
|
||||
auto* reactions = element->custom_element_reaction_queue();
|
||||
|
||||
// 3. Repeat until reactions is empty:
|
||||
while (!reactions.is_empty()) {
|
||||
if (!reactions)
|
||||
continue;
|
||||
while (!reactions->is_empty()) {
|
||||
// 1. Remove the first element of reactions, and let reaction be that element. Switch on reaction's type:
|
||||
auto reaction = reactions.take_first();
|
||||
auto reaction = reactions->take_first();
|
||||
|
||||
auto maybe_exception = reaction.visit(
|
||||
[&](DOM::CustomElementUpgradeReaction const& custom_element_upgrade_reaction) -> JS::ThrowCompletionOr<void> {
|
||||
|
@ -1811,7 +1811,7 @@ void Element::enqueue_an_element_on_the_appropriate_element_queue()
|
||||
void Element::enqueue_a_custom_element_upgrade_reaction(HTML::CustomElementDefinition& custom_element_definition)
|
||||
{
|
||||
// 1. Add a new upgrade reaction to element's custom element reaction queue, with custom element definition definition.
|
||||
m_custom_element_reaction_queue.append(CustomElementUpgradeReaction { .custom_element_definition = custom_element_definition });
|
||||
ensure_custom_element_reaction_queue().append(CustomElementUpgradeReaction { .custom_element_definition = custom_element_definition });
|
||||
|
||||
// 2. Enqueue an element on the appropriate element queue given element.
|
||||
enqueue_an_element_on_the_appropriate_element_queue();
|
||||
@ -1846,7 +1846,7 @@ void Element::enqueue_a_custom_element_callback_reaction(FlyString const& callba
|
||||
}
|
||||
|
||||
// 5. Add a new callback reaction to element's custom element reaction queue, with callback function callback and arguments args.
|
||||
m_custom_element_reaction_queue.append(CustomElementCallbackReaction { .callback = callback_iterator->value, .arguments = move(arguments) });
|
||||
ensure_custom_element_reaction_queue().append(CustomElementCallbackReaction { .callback = callback_iterator->value, .arguments = move(arguments) });
|
||||
|
||||
// 6. Enqueue an element on the appropriate element queue given element.
|
||||
enqueue_an_element_on_the_appropriate_element_queue();
|
||||
@ -1929,7 +1929,7 @@ JS::ThrowCompletionOr<void> Element::upgrade_element(JS::NonnullGCPtr<HTML::Cust
|
||||
m_custom_element_definition = nullptr;
|
||||
|
||||
// 2. Empty element's custom element reaction queue.
|
||||
m_custom_element_reaction_queue.clear();
|
||||
m_custom_element_reaction_queue = nullptr;
|
||||
|
||||
// 3. Rethrow the exception (thus terminating this algorithm).
|
||||
return maybe_exception.release_error();
|
||||
@ -2271,4 +2271,11 @@ void Element::attribute_change_steps(FlyString const& local_name, Optional<Strin
|
||||
}
|
||||
}
|
||||
|
||||
auto Element::ensure_custom_element_reaction_queue() -> CustomElementReactionQueue&
|
||||
{
|
||||
if (!m_custom_element_reaction_queue)
|
||||
m_custom_element_reaction_queue = make<CustomElementReactionQueue>();
|
||||
return *m_custom_element_reaction_queue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -325,8 +325,10 @@ public:
|
||||
void enqueue_a_custom_element_upgrade_reaction(HTML::CustomElementDefinition& custom_element_definition);
|
||||
void enqueue_a_custom_element_callback_reaction(FlyString const& callback_name, JS::MarkedVector<JS::Value> arguments);
|
||||
|
||||
Vector<Variant<CustomElementUpgradeReaction, CustomElementCallbackReaction>>& custom_element_reaction_queue() { return m_custom_element_reaction_queue; }
|
||||
Vector<Variant<CustomElementUpgradeReaction, CustomElementCallbackReaction>> const& custom_element_reaction_queue() const { return m_custom_element_reaction_queue; }
|
||||
using CustomElementReactionQueue = Vector<Variant<CustomElementUpgradeReaction, CustomElementCallbackReaction>>;
|
||||
CustomElementReactionQueue* custom_element_reaction_queue() { return m_custom_element_reaction_queue; }
|
||||
CustomElementReactionQueue const* custom_element_reaction_queue() const { return m_custom_element_reaction_queue; }
|
||||
CustomElementReactionQueue& ensure_custom_element_reaction_queue();
|
||||
|
||||
JS::ThrowCompletionOr<void> upgrade_element(JS::NonnullGCPtr<HTML::CustomElementDefinition> custom_element_definition);
|
||||
void try_to_upgrade();
|
||||
@ -416,7 +418,7 @@ private:
|
||||
// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element-reaction-queue
|
||||
// All elements have an associated custom element reaction queue, initially empty. Each item in the custom element reaction queue is of one of two types:
|
||||
// NOTE: See the structs at the top of this header.
|
||||
Vector<Variant<CustomElementUpgradeReaction, CustomElementCallbackReaction>> m_custom_element_reaction_queue;
|
||||
OwnPtr<CustomElementReactionQueue> m_custom_element_reaction_queue;
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-custom-element-state
|
||||
CustomElementState m_custom_element_state { CustomElementState::Undefined };
|
||||
|
Loading…
Reference in New Issue
Block a user