1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:47:45 +00:00

LibWeb: Allocate custom element reactions queue on demand

This shrinks most DOM elements by 16 bytes.
This commit is contained in:
Andreas Kling 2023-11-19 21:53:58 +01:00
parent ac8bb89f50
commit 7ee47d81ca
3 changed files with 20 additions and 9 deletions

View file

@ -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;
}
}