Skip to content

Commit

Permalink
Cherry-pick c602819. rdar://124128482
Browse files Browse the repository at this point in the history
    Inline CustomElementElementQueue into CustomElementReactionStack
    https://bugs.webkit.org/show_bug.cgi?id=270551

    Reviewed by Chris Dumez.

    Inline CustomElementElementQueue into CustomElementReactionStack to avoid heap allocation.

    * Source/WebCore/dom/CustomElementReactionQueue.cpp:
    (WebCore::CustomElementQueue::processQueue):
    (WebCore::CustomElementReactionQueue::enqueueElementOnAppropriateElementQueue):
    (WebCore::CustomElementReactionStack::processQueue): Deleted.
    (WebCore::CustomElementReactionStack::takeElements): Deleted.
    * Source/WebCore/dom/CustomElementReactionQueue.h:
    (WebCore::CustomElementQueue::CustomElementQueue): Inlined.
    (WebCore::CustomElementQueue::~CustomElementQueue): Ditto.
    (WebCore::CustomElementQueue::isEmpty const): Added.
    (WebCore::CustomElementReactionStack::~CustomElementReactionStack):
    (WebCore::CustomElementReactionStack::takeElements): Inlined.
    * Source/WebCore/dom/GCReachableRef.h:

    Canonical link: https://commits.webkit.org/275734@main
  • Loading branch information
rniwa authored and Mohsin Qureshi committed Mar 12, 2024
1 parent a7f78bd commit 29e879e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
26 changes: 2 additions & 24 deletions Source/WebCore/dom/CustomElementReactionQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,6 @@ void CustomElementReactionQueue::invokeAll(Element& element)
}
}

CustomElementQueue::CustomElementQueue() = default;
CustomElementQueue::~CustomElementQueue() = default;

inline void CustomElementQueue::add(Element& element)
{
ASSERT(!m_invoking);
Expand All @@ -346,7 +343,7 @@ inline void CustomElementQueue::invokeAll()
m_elements.clear();
}

inline void CustomElementQueue::processQueue(JSC::JSGlobalObject* state)
void CustomElementQueue::processQueue(JSC::JSGlobalObject* state)
{
if (!state) {
invokeAll();
Expand Down Expand Up @@ -393,10 +390,7 @@ void CustomElementReactionQueue::enqueueElementOnAppropriateElementQueue(Element
return;
}

auto& queue = CustomElementReactionStack::s_currentProcessingStack->m_queue;
if (!queue)
queue = makeUnique<CustomElementQueue>();
queue->add(element);
CustomElementReactionStack::s_currentProcessingStack->m_queue.add(element);
}

#if ASSERT_ENABLED
Expand All @@ -405,22 +399,6 @@ unsigned CustomElementReactionDisallowedScope::s_customElementReactionDisallowed

CustomElementReactionStack* CustomElementReactionStack::s_currentProcessingStack = nullptr;

void CustomElementReactionStack::processQueue(JSC::JSGlobalObject* state)
{
ASSERT(m_queue);
m_queue->processQueue(state);
m_queue = nullptr;
}

Vector<GCReachableRef<Element>, 4> CustomElementReactionStack::takeElements()
{
if (!m_queue)
return { };
auto elements = m_queue->takeElements();
m_queue = nullptr;
return elements;
}

void CustomElementReactionQueue::processBackupQueue(CustomElementQueue& backupElementQueue)
{
backupElementQueue.processQueue(nullptr);
Expand Down
18 changes: 9 additions & 9 deletions Source/WebCore/dom/CustomElementReactionQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include "CustomElementFormValue.h"
#include "Element.h"
#include "GCReachableRef.h"
#include "QualifiedName.h"
#include <wtf/CheckedRef.h>
Expand Down Expand Up @@ -99,11 +100,12 @@ class CustomElementQueue {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(CustomElementQueue);
public:
CustomElementQueue();
WEBCORE_EXPORT ~CustomElementQueue();
CustomElementQueue() = default;
~CustomElementQueue() { ASSERT(isEmpty()); }

bool isEmpty() const { return m_elements.isEmpty(); }
void add(Element&);
void processQueue(JSC::JSGlobalObject*);
WEBCORE_EXPORT void processQueue(JSC::JSGlobalObject*);

Vector<GCReachableRef<Element>, 4> takeElements();

Expand Down Expand Up @@ -224,17 +226,15 @@ class CustomElementReactionStack : public CustomElementReactionDisallowedScope::

ALWAYS_INLINE ~CustomElementReactionStack()
{
if (UNLIKELY(m_queue))
processQueue(m_state);
if (UNLIKELY(!m_queue.isEmpty()))
m_queue.processQueue(m_state);
s_currentProcessingStack = m_previousProcessingStack;
}

Vector<GCReachableRef<Element>, 4> takeElements();
Vector<GCReachableRef<Element>, 4> takeElements() { return m_queue.takeElements(); }

private:
WEBCORE_EXPORT void processQueue(JSC::JSGlobalObject*);

std::unique_ptr<CustomElementQueue> m_queue;
CustomElementQueue m_queue;
CustomElementReactionStack* const m_previousProcessingStack;
JSC::JSGlobalObject* const m_state;

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/GCReachableRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GCReachableRefMap {
}

private:
static HashCountedSet<EventTarget*>& map();
WEBCORE_EXPORT static HashCountedSet<EventTarget*>& map();
};

template <typename T, typename = std::enable_if_t<std::is_same<T, typename std::remove_const<T>::type>::value>>
Expand Down

0 comments on commit 29e879e

Please sign in to comment.