Commit 372218eb authored by esprehn@chromium.org's avatar esprehn@chromium.org

Avoid duplicate hash lookups in CustomElementScheduler::ensureCallbackQueue

We can use add() to avoid doing two hash lookups in the common case where
there's no callback queue yet (ex. setting a new attribute) and we can
also return a reference.

Review URL: https://codereview.chromium.org/206623006

git-svn-id: svn://svn.chromium.org/blink/trunk@169920 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b7854d8c
...@@ -48,8 +48,8 @@ class HTMLImport; ...@@ -48,8 +48,8 @@ class HTMLImport;
void CustomElementScheduler::scheduleCreatedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element) void CustomElementScheduler::scheduleCreatedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
{ {
CustomElementCallbackQueue* queue = instance().schedule(element); CustomElementCallbackQueue& queue = instance().schedule(element);
queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::Created)); queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::Created));
} }
void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
...@@ -57,8 +57,8 @@ void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE ...@@ -57,8 +57,8 @@ void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE
if (!callbacks->hasAttributeChangedCallback()) if (!callbacks->hasAttributeChangedCallback())
return; return;
CustomElementCallbackQueue* queue = instance().schedule(element); CustomElementCallbackQueue& queue = instance().schedule(element);
queue->append(CustomElementCallbackInvocation::createAttributeChangedInvocation(callbacks, name, oldValue, newValue)); queue.append(CustomElementCallbackInvocation::createAttributeChangedInvocation(callbacks, name, oldValue, newValue));
} }
void CustomElementScheduler::scheduleAttachedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element) void CustomElementScheduler::scheduleAttachedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
...@@ -66,8 +66,8 @@ void CustomElementScheduler::scheduleAttachedCallback(PassRefPtr<CustomElementLi ...@@ -66,8 +66,8 @@ void CustomElementScheduler::scheduleAttachedCallback(PassRefPtr<CustomElementLi
if (!callbacks->hasAttachedCallback()) if (!callbacks->hasAttachedCallback())
return; return;
CustomElementCallbackQueue* queue = instance().schedule(element); CustomElementCallbackQueue& queue = instance().schedule(element);
queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::Attached)); queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::Attached));
} }
void CustomElementScheduler::scheduleDetachedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element) void CustomElementScheduler::scheduleDetachedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
...@@ -75,8 +75,8 @@ void CustomElementScheduler::scheduleDetachedCallback(PassRefPtr<CustomElementLi ...@@ -75,8 +75,8 @@ void CustomElementScheduler::scheduleDetachedCallback(PassRefPtr<CustomElementLi
if (!callbacks->hasDetachedCallback()) if (!callbacks->hasDetachedCallback())
return; return;
CustomElementCallbackQueue* queue = instance().schedule(element); CustomElementCallbackQueue& queue = instance().schedule(element);
queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::Detached)); queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::Detached));
} }
void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtr<CustomElementRegistrationContext> context, PassRefPtr<Element> element, const CustomElementDescriptor& descriptor) void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtr<CustomElementRegistrationContext> context, PassRefPtr<Element> element, const CustomElementDescriptor& descriptor)
...@@ -112,13 +112,12 @@ CustomElementScheduler& CustomElementScheduler::instance() ...@@ -112,13 +112,12 @@ CustomElementScheduler& CustomElementScheduler::instance()
return instance; return instance;
} }
CustomElementCallbackQueue* CustomElementScheduler::ensureCallbackQueue(PassRefPtr<Element> element) CustomElementCallbackQueue& CustomElementScheduler::ensureCallbackQueue(PassRefPtr<Element> element)
{ {
Element* key = element.get(); ElementCallbackQueueMap::ValueType* it = m_elementCallbackQueueMap.add(element.get(), nullptr).storedValue;
ElementCallbackQueueMap::iterator it = m_elementCallbackQueueMap.find(key); if (!it->value)
if (it == m_elementCallbackQueueMap.end()) it->value = CustomElementCallbackQueue::create(element);
return m_elementCallbackQueueMap.add(key, CustomElementCallbackQueue::create(element)).storedValue->value.get(); return *it->value.get();
return it->value.get();
} }
void CustomElementScheduler::callbackDispatcherDidFinish() void CustomElementScheduler::callbackDispatcherDidFinish()
...@@ -140,12 +139,12 @@ void CustomElementScheduler::clearElementCallbackQueueMap() ...@@ -140,12 +139,12 @@ void CustomElementScheduler::clearElementCallbackQueueMap()
} }
// Finds or creates the callback queue for element. // Finds or creates the callback queue for element.
CustomElementCallbackQueue* CustomElementScheduler::schedule(PassRefPtr<Element> passElement) CustomElementCallbackQueue& CustomElementScheduler::schedule(PassRefPtr<Element> passElement)
{ {
RefPtr<Element> element(passElement); RefPtr<Element> element(passElement);
CustomElementCallbackQueue* callbackQueue = ensureCallbackQueue(element); CustomElementCallbackQueue& callbackQueue = ensureCallbackQueue(element);
if (callbackQueue->inCreatedCallback()) { if (callbackQueue.inCreatedCallback()) {
// Don't move it. Authors use the createdCallback like a // Don't move it. Authors use the createdCallback like a
// constructor. By not moving it, the createdCallback // constructor. By not moving it, the createdCallback
// completes before any other callbacks are entered for this // completes before any other callbacks are entered for this
...@@ -155,11 +154,11 @@ CustomElementCallbackQueue* CustomElementScheduler::schedule(PassRefPtr<Element> ...@@ -155,11 +154,11 @@ CustomElementCallbackQueue* CustomElementScheduler::schedule(PassRefPtr<Element>
if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) {
// The processing stack is active. // The processing stack is active.
CustomElementCallbackDispatcher::instance().enqueue(callbackQueue); CustomElementCallbackDispatcher::instance().enqueue(&callbackQueue);
return callbackQueue; return callbackQueue;
} }
CustomElementMicrotaskDispatcher::instance().enqueue(callbackQueue); CustomElementMicrotaskDispatcher::instance().enqueue(&callbackQueue);
return callbackQueue; return callbackQueue;
} }
......
...@@ -63,8 +63,8 @@ private: ...@@ -63,8 +63,8 @@ private:
static CustomElementScheduler& instance(); static CustomElementScheduler& instance();
CustomElementCallbackQueue* ensureCallbackQueue(PassRefPtr<Element>); CustomElementCallbackQueue& ensureCallbackQueue(PassRefPtr<Element>);
CustomElementCallbackQueue* schedule(PassRefPtr<Element>); CustomElementCallbackQueue& schedule(PassRefPtr<Element>);
// FIXME: Consider moving the element's callback queue to // FIXME: Consider moving the element's callback queue to
// ElementRareData. Then the scheduler can become completely // ElementRareData. Then the scheduler can become completely
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment