Do a bit of EventNames tidying
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Mar 2015 21:51:33 +0000 (21:51 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Mar 2015 21:51:33 +0000 (21:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142438

Reviewed by Anders Carlsson.

* dom/EventNames.h: Sorted the event names into a single list instead of
the rudimentary attempts at organizing the list that simply made it hard
to see what is and is not in the list. Removed two unused event names.
I'm sure there are more. Reorganized the EventName class, now a struct,
into a more conventional "public first" order. Got the function bodies
out of the struct so we can see more clearly what is in the struct.
Made more things const.
(WebCore::EventNames::touchEventNames): Changed the return value to a
std::array of reference wrappers rather than a vector of atomic strings.
This should eliminate unnecessary memory allocation and reference count churn.

* dom/EventNames.cpp: Changed initialization based on the above.

* dom/EventTarget.cpp:
(WebCore::EventTarget::getEventListeners): Use NeverDestroyed instead of
DEPRECATED_DEFINE_LOCAL and also just tightened up the function a bit.

* dom/Node.cpp:
(WebCore::Node::didMoveToNewDocument): Streamlined this function with
modern for loops, auto, and also tried to make what it does a bit clearer,
by making loops that are just based on numbers of event listeners look a
bit less like code that actually iterates a vector of listeners. Also used
the type unsigned instead of size_t.

* platform/ThreadGlobalData.h: Updated since it's a struct instead of class now.
(Why is this file in platform!?)

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181212 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/EventNames.cpp
Source/WebCore/dom/EventNames.h
Source/WebCore/dom/EventTarget.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/platform/ThreadGlobalData.h

index 6d8ceb978295e3cd71277b21e1b7c2f89d14af69..1773b2158f68e37e3a8d8b1982169e295ea6a44e 100644 (file)
@@ -1,3 +1,37 @@
+2015-03-07  Darin Adler  <darin@apple.com>
+
+        Do a bit of EventNames tidying
+        https://bugs.webkit.org/show_bug.cgi?id=142438
+
+        Reviewed by Anders Carlsson.
+
+        * dom/EventNames.h: Sorted the event names into a single list instead of
+        the rudimentary attempts at organizing the list that simply made it hard
+        to see what is and is not in the list. Removed two unused event names.
+        I'm sure there are more. Reorganized the EventName class, now a struct,
+        into a more conventional "public first" order. Got the function bodies
+        out of the struct so we can see more clearly what is in the struct.
+        Made more things const.
+        (WebCore::EventNames::touchEventNames): Changed the return value to a
+        std::array of reference wrappers rather than a vector of atomic strings.
+        This should eliminate unnecessary memory allocation and reference count churn.
+
+        * dom/EventNames.cpp: Changed initialization based on the above.
+
+        * dom/EventTarget.cpp:
+        (WebCore::EventTarget::getEventListeners): Use NeverDestroyed instead of
+        DEPRECATED_DEFINE_LOCAL and also just tightened up the function a bit.
+
+        * dom/Node.cpp:
+        (WebCore::Node::didMoveToNewDocument): Streamlined this function with
+        modern for loops, auto, and also tried to make what it does a bit clearer,
+        by making loops that are just based on numbers of event listeners look a
+        bit less like code that actually iterates a vector of listeners. Also used
+        the type unsigned instead of size_t.
+
+        * platform/ThreadGlobalData.h: Updated since it's a struct instead of class now.
+        (Why is this file in platform!?)
+
 2015-03-07  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] Increase TestWebKitAPI Test Coverage
index 6c5f20ecf959ff13e62ffa6cffcffac43630605b..fcc5601fc60101737146d5619930cf6e9bdeaa6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005 Apple Inc.
+ * Copyright (C) 2005, 2015 Apple Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 namespace WebCore {
 
 #define INITIALIZE_EVENT_NAME(name) \
-    , name##Event(#name, AtomicString::ConstructFromLiteral)
+    name##Event(#name, AtomicString::ConstructFromLiteral),
 
 EventNames::EventNames()
-    : dummy(0)
-    DOM_EVENT_NAMES_FOR_EACH(INITIALIZE_EVENT_NAME)
+    : DOM_EVENT_NAMES_FOR_EACH(INITIALIZE_EVENT_NAME) dummy(0)
 {
 }
 
index 2dacec41f745ed39dba711cc85f7976a7eb157a6..760e7d536b4ba4b55a396d2c0db5d75f2695349a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2007, 2015 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
  *
  * This library is free software; you can redistribute it and/or
 #define EventNames_h
 
 #include "ThreadGlobalData.h"
+#include <array>
+#include <functional>
 #include <wtf/text/AtomicString.h>
 
 namespace WebCore {
 
 #define DOM_EVENT_NAMES_FOR_EACH(macro) \
-    \
+    macro(DOMActivate) \
+    macro(DOMCharacterDataModified) \
+    macro(DOMContentLoaded) \
+    macro(DOMFocusIn) \
+    macro(DOMFocusOut) \
+    macro(DOMNodeInserted) \
+    macro(DOMNodeInsertedIntoDocument) \
+    macro(DOMNodeRemoved) \
+    macro(DOMNodeRemovedFromDocument) \
+    macro(DOMSubtreeModified) \
     macro(abort) \
+    macro(active) \
+    macro(addsourcebuffer) \
+    macro(addstream) \
+    macro(addtrack) \
+    macro(animationend) \
+    macro(animationiteration) \
+    macro(animationstart) \
+    macro(audioend) \
+    macro(audioprocess) \
+    macro(audiostart) \
+    macro(autocomplete) \
+    macro(autocompleteerror) \
     macro(beforecopy) \
     macro(beforecut) \
     macro(beforeload) \
@@ -37,7 +60,10 @@ namespace WebCore {
     macro(beforeunload) \
     macro(blocked) \
     macro(blur) \
+    macro(boundary) \
     macro(cached) \
+    macro(canplay) \
+    macro(canplaythrough) \
     macro(change) \
     macro(chargingchange) \
     macro(chargingtimechange) \
@@ -49,14 +75,16 @@ namespace WebCore {
     macro(compositionstart) \
     macro(compositionupdate) \
     macro(connect) \
+    macro(connecting) \
     macro(contextmenu) \
     macro(copy) \
+    macro(cuechange) \
     macro(cut) \
+    macro(datachannel) \
     macro(dblclick) \
     macro(devicemotion) \
     macro(deviceorientation) \
     macro(dischargingtimechange) \
-    macro(display) \
     macro(downloading) \
     macro(drag) \
     macro(dragend) \
@@ -65,16 +93,30 @@ namespace WebCore {
     macro(dragover) \
     macro(dragstart) \
     macro(drop) \
+    macro(durationchange) \
+    macro(emptied) \
+    macro(end) \
+    macro(ended) \
+    macro(enter) \
     macro(error) \
+    macro(exit) \
     macro(focus) \
     macro(focusin) \
     macro(focusout) \
-    macro(gesturetap) \
-    macro(gesturetapdown) \
-    macro(gesturescrollstart) \
+    macro(gamepadconnected) \
+    macro(gamepaddisconnected) \
+    macro(gesturechange) \
+    macro(gestureend) \
     macro(gesturescrollend) \
+    macro(gesturescrollstart) \
     macro(gesturescrollupdate) \
+    macro(gesturestart) \
+    macro(gesturetap) \
+    macro(gesturetapdown) \
     macro(hashchange) \
+    macro(icecandidate) \
+    macro(iceconnectionstatechange) \
+    macro(inactive) \
     macro(input) \
     macro(invalid) \
     macro(keydown) \
@@ -82,9 +124,13 @@ namespace WebCore {
     macro(keyup) \
     macro(levelchange) \
     macro(load) \
+    macro(loadeddata) \
+    macro(loadedmetadata) \
+    macro(loadend) \
     macro(loading) \
     macro(loadingdone) \
     macro(loadstart) \
+    macro(mark) \
     macro(message) \
     macro(mousedown) \
     macro(mouseenter) \
@@ -94,263 +140,180 @@ namespace WebCore {
     macro(mouseover) \
     macro(mouseup) \
     macro(mousewheel) \
+    macro(mute) \
+    macro(negotiationneeded) \
+    macro(nomatch) \
     macro(noupdate) \
     macro(obsolete) \
     macro(offline) \
     macro(online) \
     macro(open) \
+    macro(orientationchange) \
+    macro(overconstrained) \
     macro(overflowchanged) \
     macro(pagehide) \
     macro(pageshow) \
     macro(paste) \
+    macro(pause) \
+    macro(play) \
+    macro(playing) \
+    macro(pointerlockchange) \
+    macro(pointerlockerror) \
     macro(popstate) \
+    macro(progress) \
+    macro(ratechange) \
     macro(readystatechange) \
+    macro(removesourcebuffer) \
+    macro(removestream) \
+    macro(removetrack) \
     macro(reset) \
     macro(resize) \
+    macro(result) \
+    macro(resume) \
     macro(scroll) \
     macro(search) \
+    macro(securitypolicyviolation) \
+    macro(seeked) \
+    macro(seeking) \
     macro(select) \
-    macro(selectstart) \
     macro(selectionchange) \
+    macro(selectstart) \
+    macro(show) \
+    macro(signalingstatechange) \
+    macro(soundend) \
+    macro(soundstart) \
+    macro(sourceclose) \
+    macro(sourceended) \
+    macro(sourceopen) \
+    macro(speechend) \
+    macro(speechstart) \
+    macro(stalled) \
+    macro(start) \
+    macro(started) \
     macro(storage) \
     macro(submit) \
+    macro(success) \
+    macro(suspend) \
     macro(textInput) \
+    macro(timeout) \
+    macro(timeupdate) \
+    macro(tonechange) \
+    macro(touchcancel) \
+    macro(touchend) \
+    macro(touchmove) \
+    macro(touchstart) \
+    macro(transitionend) \
     macro(unload) \
+    macro(unmute) \
+    macro(update) \
+    macro(updateend) \
     macro(updateready) \
+    macro(updatestart) \
     macro(upgradeneeded) \
     macro(versionchange) \
     macro(visibilitychange) \
-    /* ENABLE(WILL_REVEAL_EDGE_EVENT) */ \
-    macro(webkitwillrevealbottom) \
-    macro(webkitwillrevealleft) \
-    macro(webkitwillrevealright) \
-    macro(webkitwillrevealtop) \
-    /* End of ENABLE(WILL_REVEAL_EDGE_EVENT) */ \
-    macro(wheel) \
-    macro(write) \
-    macro(writeend) \
-    macro(writestart) \
-    macro(zoom) \
-    \
-    macro(DOMActivate) \
-    macro(DOMFocusIn) \
-    macro(DOMFocusOut) \
-    macro(DOMCharacterDataModified) \
-    macro(DOMNodeInserted) \
-    macro(DOMNodeInsertedIntoDocument) \
-    macro(DOMNodeRemoved) \
-    macro(DOMNodeRemovedFromDocument) \
-    macro(DOMSubtreeModified) \
-    macro(DOMContentLoaded) \
-    \
-    macro(webkitBeforeTextInserted) \
-    macro(webkitEditableContentChanged) \
-    \
-    macro(canplay) \
-    macro(canplaythrough) \
-    macro(durationchange) \
-    macro(emptied) \
-    macro(ended) \
-    macro(loadeddata) \
-    macro(loadedmetadata) \
-    macro(pause) \
-    macro(play) \
-    macro(playing) \
-    macro(ratechange) \
-    macro(seeked) \
-    macro(seeking) \
-    macro(timeupdate) \
     macro(volumechange) \
     macro(waiting) \
-    \
-    macro(active) \
-    macro(inactive) \
-    macro(addtrack) \
-    macro(cuechange) \
-    macro(enter) \
-    macro(exit) \
-    \
+    macro(webglcontextcreationerror) \
+    macro(webglcontextlost) \
+    macro(webglcontextrestored) \
+    macro(webkitAnimationEnd) \
+    macro(webkitAnimationIteration) \
+    macro(webkitAnimationStart) \
+    macro(webkitBeforeTextInserted) \
+    macro(webkitEditableContentChanged) \
+    macro(webkitTransitionEnd) \
     macro(webkitbeginfullscreen) \
+    macro(webkitcurrentplaybacktargetiswirelesschanged) \
+    macro(webkitdeviceproximity) \
     macro(webkitendfullscreen) \
-    \
-    macro(addsourcebuffer) \
-    macro(removesourcebuffer) \
-    macro(sourceopen) \
-    macro(sourceended) \
-    macro(sourceclose) \
-    macro(update) \
-    macro(updateend) \
-    macro(updatestart) \
-    macro(webkitaddsourcebuffer) \
-    macro(webkitremovesourcebuffer) \
-    macro(webkitsourceopen) \
-    macro(webkitsourceended) \
-    macro(webkitsourceclose) \
-    \
+    macro(webkitfullscreenchange) \
+    macro(webkitfullscreenerror) \
     macro(webkitkeyadded) \
     macro(webkitkeyerror) \
     macro(webkitkeymessage) \
     macro(webkitneedkey) \
-    \
-    macro(progress) \
-    macro(stalled) \
-    macro(suspend) \
-    \
-    macro(webkitAnimationEnd) \
-    macro(webkitAnimationStart) \
-    macro(webkitAnimationIteration) \
-    macro(animationend) \
-    macro(animationstart) \
-    macro(animationiteration) \
-    \
-    macro(webkitTransitionEnd) \
-    macro(transitionend) \
-    \
-    macro(orientationchange) \
-    \
-    macro(timeout) \
-    \
-    macro(touchstart) \
-    macro(touchmove) \
-    macro(touchend) \
-    macro(touchcancel) \
-    \
-    macro(success) \
-    \
-    macro(loadend) \
-    \
-    macro(webkitfullscreenchange) \
-    macro(webkitfullscreenerror) \
-    \
-    macro(webkitspeechchange) \
-    \
-    macro(audiostart) \
-    macro(soundstart) \
-    macro(speechstart) \
-    macro(speechend) \
-    macro(soundend) \
-    macro(audioend) \
-    macro(result) \
-    macro(nomatch) \
-    macro(start) \
-    macro(end) \
-    macro(mark) \
-    macro(boundary) \
-    macro(resume) \
-    \
-    macro(webglcontextlost) \
-    macro(webglcontextrestored) \
-    macro(webglcontextcreationerror) \
-    \
-    macro(audioprocess) \
-    \
-    macro(connecting) \
-    macro(addstream) \
-    macro(removestream) \
-    macro(signalingstatechange) \
-    macro(removetrack) \
-    macro(overconstrained) \
-    macro(mute) \
-    macro(unmute) \
-    macro(started) \
-    macro(iceconnectionstatechange) \
-    macro(icecandidate) \
-    macro(negotiationneeded) \
-    macro(datachannel) \
-    macro(tonechange) \
-    \
-    macro(show) \
-    \
-    macro(pointerlockchange) \
-    macro(pointerlockerror) \
-    \
-    macro(webkitregionoversetchange) \
-    \
     macro(webkitnetworkinfochange) \
-    \
-    macro(webkitresourcetimingbufferfull) \
-    \
-    macro(webkitdeviceproximity) \
-    \
-    macro(securitypolicyviolation) \
-    \
-    /* ENABLE(WIRELESS_PLAYBACK_TARGET) */ \
-    macro(webkitcurrentplaybacktargetiswirelesschanged) \
     macro(webkitplaybacktargetavailabilitychanged) \
-    /* End of ENABLE(WIRELESS_PLAYBACK_TARGET) */ \
-    \
-    /* ENABLE(IOS_GESTURE_EVENTS) */ \
-    macro(gesturestart) \
-    macro(gesturechange) \
-    macro(gestureend) \
-    /* End of ENABLE(IOS_GESTURE_EVENTS) */ \
-    \
-    /* ENABLE(GAMEPAD) */ \
-    macro(gamepadconnected) \
-    macro(gamepaddisconnected) \
-    /* End of ENABLE(GAMEPAD) */ \
-    \
-    /* ENABLE(REQUEST_AUTOCOMPLETE) */ \
-    macro(autocomplete) \
-    macro(autocompleteerror) \
-    /* End of ENABLE(REQUEST_AUTOCOMPLETE) */ \
-    \
-    /* PLATFORM(IOS) */ \
     macro(webkitpresentationmodechanged) \
-    /* End of ENABLE(WIRELESS_PLAYBACK_TARGET) */ \
-
+    macro(webkitregionoversetchange) \
+    macro(webkitremovesourcebuffer) \
+    macro(webkitresourcetimingbufferfull) \
+    macro(webkitsourceclose) \
+    macro(webkitsourceended) \
+    macro(webkitsourceopen) \
+    macro(webkitspeechchange) \
+    macro(webkitwillrevealbottom) \
+    macro(webkitwillrevealleft) \
+    macro(webkitwillrevealright) \
+    macro(webkitwillrevealtop) \
+    macro(wheel) \
+    macro(write) \
+    macro(writeend) \
+    macro(writestart) \
+    macro(zoom) \
 // end of DOM_EVENT_NAMES_FOR_EACH
 
-class EventNames {
+struct EventNames {
     WTF_MAKE_NONCOPYABLE(EventNames); WTF_MAKE_FAST_ALLOCATED;
-    int dummy; // Needed to make initialization macro work.
-    // Private to prevent accidental call to EventNames() instead of eventNames()
-    EventNames();
-    friend class ThreadGlobalData;
 
 public:
-    #define DOM_EVENT_NAMES_DECLARE(name) AtomicString name##Event;
+#define DOM_EVENT_NAMES_DECLARE(name) const AtomicString name##Event;
     DOM_EVENT_NAMES_FOR_EACH(DOM_EVENT_NAMES_DECLARE)
-    #undef DOM_EVENT_NAMES_DECLARE
+#undef DOM_EVENT_NAMES_DECLARE
 
-    inline bool isGestureEventType(const AtomicString& eventType) const
-    {
-        return eventType == gesturestartEvent || eventType == gesturechangeEvent || eventType == gestureendEvent;
-    }
+    // FIXME: Inelegant to call these both event names and event types.
+    // We should choose one term and stick to it.
+    bool isGestureEventType(const AtomicString& eventType) const;
+    bool isTouchEventType(const AtomicString& eventType) const;
+#if ENABLE(GAMEPAD)
+    bool isGamepadEventType(const AtomicString& eventType) const;
+#endif
 
-    inline bool isTouchEventType(const AtomicString& eventType) const
-    {
-        return eventType == touchstartEvent
-            || eventType == touchmoveEvent
-            || eventType == touchendEvent
-            || eventType == touchcancelEvent;
-    }
+    std::array<std::reference_wrapper<const AtomicString>, 4> touchEventNames() const;
 
-    Vector<AtomicString> touchEventNames() const
-    {
-        Vector<AtomicString> names;
-        names.reserveCapacity(4);
-        names.append(touchstartEvent);
-        names.append(touchmoveEvent);
-        names.append(touchendEvent);
-        names.append(touchcancelEvent);
-        return names;
-    }
+private:
+    EventNames(); // Private to prevent accidental call to EventNames() instead of eventNames().
+    friend class ThreadGlobalData; // Allow ThreadGlobalData to create the per-thread EventNames object.
 
-#if ENABLE(GAMEPAD)
-    inline bool isGamepadEventType(const AtomicString& eventType) const
-    {
-        return eventType == gamepadconnectedEvent
-            || eventType == gamepaddisconnectedEvent;
-    }
-#endif
+    int dummy; // Needed to make initialization macro work.
 };
 
-inline EventNames& eventNames()
+const EventNames& eventNames();
+
+inline const EventNames& eventNames()
 {
     return threadGlobalData().eventNames();
 }
 
+inline bool EventNames::isGestureEventType(const AtomicString& eventType) const
+{
+    return eventType == gesturestartEvent || eventType == gesturechangeEvent || eventType == gestureendEvent;
+}
+
+inline bool EventNames::isTouchEventType(const AtomicString& eventType) const
+{
+    return eventType == touchstartEvent
+        || eventType == touchmoveEvent
+        || eventType == touchendEvent
+        || eventType == touchcancelEvent;
+}
+
+inline std::array<std::reference_wrapper<const AtomicString>, 4> EventNames::touchEventNames() const
+{
+    return { { touchstartEvent, touchmoveEvent, touchendEvent, touchcancelEvent } };
+}
+
+#if ENABLE(GAMEPAD)
+
+inline bool EventNames::isGamepadEventType(const AtomicString& eventType) const
+{
+    return eventType == gamepadconnectedEvent
+        || eventType == gamepaddisconnectedEvent;
+}
+
+#endif
+
 }
 
 #endif
index 7f3895b1766caf4d5d30c875b70f541c6aa0522a..ffe786495da91f96fcc83276fc8699383d20ec86 100644 (file)
@@ -38,6 +38,7 @@
 #include "WebKitAnimationEvent.h"
 #include "WebKitTransitionEvent.h"
 #include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/Ref.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/Vector.h>
@@ -263,17 +264,10 @@ void EventTarget::fireEventListeners(Event* event, EventTargetData* d, EventList
 
 const EventListenerVector& EventTarget::getEventListeners(const AtomicString& eventType)
 {
-    DEPRECATED_DEFINE_STATIC_LOCAL(EventListenerVector, emptyVector, ());
-
-    EventTargetData* d = eventTargetData();
-    if (!d)
-        return emptyVector;
-
-    EventListenerVector* listenerVector = d->eventListenerMap.find(eventType);
-    if (!listenerVector)
-        return emptyVector;
-
-    return *listenerVector;
+    auto* data = eventTargetData();
+    auto* listenerVector = data ? data->eventListenerMap.find(eventType) : nullptr;
+    static NeverDestroyed<EventListenerVector> emptyVector;
+    return listenerVector ? *listenerVector : emptyVector.get();
 }
 
 void EventTarget::removeAllEventListeners()
index 873f31e020d602740d562ce796d5336a0c613514..126db216dbea4d17b96ba2e24eef81aa9c6a48e8 100644 (file)
@@ -1700,47 +1700,40 @@ void Node::didMoveToNewDocument(Document* oldDocument)
 {
     TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(oldDocument);
 
-    if (const EventTargetData* eventTargetData = this->eventTargetData()) {
-        const EventListenerMap& listenerMap = eventTargetData->eventListenerMap;
-        if (!listenerMap.isEmpty()) {
-            Vector<AtomicString> types = listenerMap.eventTypes();
-            for (unsigned i = 0; i < types.size(); ++i)
-                document().addListenerTypeIfNeeded(types[i]);
+    if (auto* eventTargetData = this->eventTargetData()) {
+        if (!eventTargetData->eventListenerMap.isEmpty()) {
+            for (auto& type : eventTargetData->eventListenerMap.eventTypes())
+                document().addListenerTypeIfNeeded(type);
         }
     }
 
-    if (AXObjectCache::accessibilityEnabled() && oldDocument)
-        if (AXObjectCache* cache = oldDocument->existingAXObjectCache())
+    if (AXObjectCache::accessibilityEnabled() && oldDocument) {
+        if (auto* cache = oldDocument->existingAXObjectCache())
             cache->remove(this);
-
-    const EventListenerVector& mousewheelListeners = getEventListeners(eventNames().mousewheelEvent);
-    for (size_t i = 0; i < mousewheelListeners.size(); ++i) {
-        oldDocument->didRemoveWheelEventHandler();
-        document().didAddWheelEventHandler();
     }
 
-    const EventListenerVector& wheelListeners = getEventListeners(eventNames().wheelEvent);
-    for (size_t i = 0; i < wheelListeners.size(); ++i) {
+    unsigned numWheelEventHandlers = getEventListeners(eventNames().mousewheelEvent).size()
+        + getEventListeners(eventNames().wheelEvent).size();
+    for (unsigned i = 0; i < numWheelEventHandlers; ++i) {
         oldDocument->didRemoveWheelEventHandler();
         document().didAddWheelEventHandler();
     }
 
-    Vector<AtomicString> touchEventNames = eventNames().touchEventNames();
-    for (size_t i = 0; i < touchEventNames.size(); ++i) {
-        const EventListenerVector& listeners = getEventListeners(touchEventNames[i]);
-        for (size_t j = 0; j < listeners.size(); ++j) {
-            oldDocument->didRemoveTouchEventHandler(this);
-            document().didAddTouchEventHandler(this);
-        }
+    unsigned numTouchEventHandlers = 0;
+    for (auto& name : eventNames().touchEventNames())
+        numTouchEventHandlers += getEventListeners(name).size();
+    for (unsigned i = 0; i < numTouchEventHandlers; ++i) {
+        oldDocument->didRemoveTouchEventHandler(this);
+        document().didAddTouchEventHandler(this);
     }
 
-    if (Vector<std::unique_ptr<MutationObserverRegistration>>* registry = mutationObserverRegistry()) {
-        for (const auto& registration : *registry)
+    if (auto* registry = mutationObserverRegistry()) {
+        for (auto& registration : *registry)
             document().addMutationObserverTypes(registration->mutationTypes());
     }
 
-    if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMutationObserverRegistry()) {
-        for (const auto& registration : *transientRegistry)
+    if (auto* transientRegistry = transientMutationObserverRegistry()) {
+        for (auto& registration : *transientRegistry)
             document().addMutationObserverTypes(registration->mutationTypes());
     }
 }
index 7e5879e8830123f2090bd303e62a7d1b8d336948..9d786d150215499c76a837020a05de9011ac3db5 100644 (file)
@@ -39,10 +39,10 @@ using WTF::ThreadSpecific;
 
 namespace WebCore {
 
-    class EventNames;
     class ThreadTimers;
 
     struct CachedResourceRequestInitiators;
+    struct EventNames;
     struct ICUConverterWrapper;
     struct TECConverterWrapper;