Use modern for-loops in WebCore/plugins, storage, style, testing and workers.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 May 2015 17:01:12 +0000 (17:01 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 May 2015 17:01:12 +0000 (17:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145425

Patch by Hunseop Jeong <hs85.jeong@samsung.com> on 2015-05-29
Reviewed by Darin Adler.

No new tests, no behavior changes.

* plugins/DOMMimeTypeArray.cpp:
(WebCore::DOMMimeTypeArray::canGetItemsForName):
* plugins/DOMPlugin.cpp:
(WebCore::DOMPlugin::canGetItemsForName):
* plugins/DOMPluginArray.cpp:
(WebCore::DOMPluginArray::canGetItemsForName):
* plugins/PluginData.cpp:
(WebCore::PluginData::getWebVisibleMimesAndPluginIndices):
* plugins/PluginMainThreadScheduler.cpp:
(WebCore::PluginMainThreadScheduler::dispatchCallsForPlugin):
(WebCore::PluginMainThreadScheduler::dispatchCalls):
* storage/StorageEventDispatcher.cpp:
(WebCore::StorageEventDispatcher::dispatchLocalStorageEvents):
(WebCore::StorageEventDispatcher::dispatchSessionStorageEventsToFrames):
(WebCore::StorageEventDispatcher::dispatchLocalStorageEventsToFrames):
* storage/StorageMap.cpp:
(WebCore::StorageMap::importItems):
* style/StyleResolveTree.cpp:
(WebCore::Style::pseudoStyleCacheIsInvalid):
* testing/Internals.cpp:
(WebCore::Internals::nodesFromRect):
* workers/Worker.cpp:
(WebCore::networkStateChanged):
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::importScripts):

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

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/plugins/DOMMimeTypeArray.cpp
Source/WebCore/plugins/DOMPlugin.cpp
Source/WebCore/plugins/DOMPluginArray.cpp
Source/WebCore/plugins/PluginData.cpp
Source/WebCore/plugins/PluginMainThreadScheduler.cpp
Source/WebCore/storage/StorageEventDispatcher.cpp
Source/WebCore/storage/StorageMap.cpp
Source/WebCore/style/StyleResolveTree.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/workers/Worker.cpp
Source/WebCore/workers/WorkerGlobalScope.cpp

index 7c188ba..3728472 100644 (file)
@@ -1,3 +1,38 @@
+2015-05-29  Hunseop Jeong  <hs85.jeong@samsung.com>
+
+        Use modern for-loops in WebCore/plugins, storage, style, testing and workers.
+        https://bugs.webkit.org/show_bug.cgi?id=145425
+
+        Reviewed by Darin Adler.
+
+        No new tests, no behavior changes.
+
+        * plugins/DOMMimeTypeArray.cpp:
+        (WebCore::DOMMimeTypeArray::canGetItemsForName):
+        * plugins/DOMPlugin.cpp:
+        (WebCore::DOMPlugin::canGetItemsForName):
+        * plugins/DOMPluginArray.cpp:
+        (WebCore::DOMPluginArray::canGetItemsForName):
+        * plugins/PluginData.cpp:
+        (WebCore::PluginData::getWebVisibleMimesAndPluginIndices):
+        * plugins/PluginMainThreadScheduler.cpp:
+        (WebCore::PluginMainThreadScheduler::dispatchCallsForPlugin):
+        (WebCore::PluginMainThreadScheduler::dispatchCalls):
+        * storage/StorageEventDispatcher.cpp:
+        (WebCore::StorageEventDispatcher::dispatchLocalStorageEvents):
+        (WebCore::StorageEventDispatcher::dispatchSessionStorageEventsToFrames):
+        (WebCore::StorageEventDispatcher::dispatchLocalStorageEventsToFrames):
+        * storage/StorageMap.cpp:
+        (WebCore::StorageMap::importItems):
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::pseudoStyleCacheIsInvalid):
+        * testing/Internals.cpp:
+        (WebCore::Internals::nodesFromRect):
+        * workers/Worker.cpp:
+        (WebCore::networkStateChanged):
+        * workers/WorkerGlobalScope.cpp:
+        (WebCore::WorkerGlobalScope::importScripts):
+
 2015-05-29  Alex Christensen  <achristensen@webkit.org>
 
         Unreviewed build fix when using content extensions debugging.
index 0e14fd3..da20449 100644 (file)
@@ -79,8 +79,8 @@ bool DOMMimeTypeArray::canGetItemsForName(const AtomicString& propertyName)
     Vector<MimeClassInfo> mimes;
     Vector<size_t> mimePluginIndices;
     data->getWebVisibleMimesAndPluginIndices(mimes, mimePluginIndices);
-    for (unsigned i = 0; i < mimes.size(); ++i) {
-        if (mimes[i].type == propertyName)
+    for (auto& mime : mimes) {
+        if (mime.type == propertyName)
             return true;
     }
     return false;
index f2488bc..e3c9664 100644 (file)
@@ -83,9 +83,10 @@ bool DOMPlugin::canGetItemsForName(const AtomicString& propertyName)
     Vector<MimeClassInfo> mimes;
     Vector<size_t> mimePluginIndices;
     m_pluginData->getWebVisibleMimesAndPluginIndices(mimes, mimePluginIndices);
-    for (unsigned i = 0; i < mimes.size(); ++i)
-        if (mimes[i].type == propertyName)
+    for (auto& mime : mimes) {
+        if (mime.type == propertyName)
             return true;
+    }
     return false;
 }
 
index 12e51a9..6bf8bd4 100644 (file)
@@ -70,9 +70,8 @@ bool DOMPluginArray::canGetItemsForName(const AtomicString& propertyName)
     if (!data)
         return 0;
 
-    const Vector<PluginInfo>& plugins = data->webVisiblePlugins();
-    for (unsigned i = 0; i < plugins.size(); ++i) {
-        if (plugins[i].name == propertyName)
+    for (auto& plugin : data->webVisiblePlugins()) {
+        if (plugin.name == propertyName)
             return true;
     }
     return false;
index 81dc18e..a178adb 100644 (file)
@@ -52,8 +52,8 @@ void PluginData::getWebVisibleMimesAndPluginIndices(Vector<MimeClassInfo>& mimes
     const Vector<PluginInfo>& plugins = webVisiblePlugins();
     for (unsigned i = 0; i < plugins.size(); ++i) {
         const PluginInfo& plugin = plugins[i];
-        for (unsigned j = 0; j < plugin.mimes.size(); ++j) {
-            mimes.append(plugin.mimes[j]);
+        for (auto& mime : plugin.mimes) {
+            mimes.append(mime);
             mimePluginIndices.append(i);
         }
     }
index acb5bb8..0ed9cce 100644 (file)
@@ -74,8 +74,7 @@ void PluginMainThreadScheduler::unregisterPlugin(NPP npp)
 
 void PluginMainThreadScheduler::dispatchCallsForPlugin(NPP npp, const Deque<Call>& calls)
 {
-    Deque<Call>::const_iterator end = calls.end();
-    for (Deque<Call>::const_iterator it = calls.begin(); it != end; ++it) {
+    for (auto& call : calls) {
         // Check if the plug-in has been destroyed.
         {
             MutexLocker lock(m_queueMutex);
@@ -83,7 +82,7 @@ void PluginMainThreadScheduler::dispatchCallsForPlugin(NPP npp, const Deque<Call
                 return;
         }
 
-        (*it).performCall();
+        call.performCall();
     }
 }
 
@@ -92,19 +91,15 @@ void PluginMainThreadScheduler::dispatchCalls()
     m_queueMutex.lock();
     CallQueueMap copy(m_callQueueMap);
 
-    {
-        // Empty all the queues in the original map
-        CallQueueMap::iterator end = m_callQueueMap.end();
-        for (CallQueueMap::iterator it = m_callQueueMap.begin(); it != end; ++it)
-            it->value.clear();
-    }
+    // Empty all the queues in the original map
+    for (auto& call : m_callQueueMap.values())
+        call.clear();
 
     m_callPending = false;
     m_queueMutex.unlock();
 
-    CallQueueMap::iterator end = copy.end();
-    for (CallQueueMap::iterator it = copy.begin(); it != end; ++it)
-        dispatchCallsForPlugin(it->key, it->value);
+    for (auto& entry : copy)
+        dispatchCallsForPlugin(entry.key, entry.value);
 }
 
 void PluginMainThreadScheduler::mainThreadCallback(void* context)
index b4de9b8..7cb42a7 100644 (file)
@@ -64,9 +64,8 @@ void StorageEventDispatcher::dispatchLocalStorageEvents(const String& key, const
     Vector<RefPtr<Frame>> frames;
 
     // Send events to every page.
-    const HashSet<Page*>& pages = page->group().pages();
-    for (HashSet<Page*>::const_iterator it = pages.begin(), end = pages.end(); it != end; ++it) {
-        for (Frame* frame = &(*it)->mainFrame(); frame; frame = frame->tree().traverseNext()) {
+    for (auto& pageInGroup : page->group().pages()) {
+        for (Frame* frame = &pageInGroup->mainFrame(); frame; frame = frame->tree().traverseNext()) {
             if (sourceFrame != frame && frame->document()->securityOrigin()->equal(securityOrigin))
                 frames.append(frame);
         }
@@ -79,25 +78,24 @@ void StorageEventDispatcher::dispatchSessionStorageEventsToFrames(Page& page, co
 {
     InspectorInstrumentation::didDispatchDOMStorageEvent(key, oldValue, newValue, SessionStorage, securityOrigin, &page);
 
-    for (unsigned i = 0; i < frames.size(); ++i) {
+    for (auto& frame : frames) {
         ExceptionCode ec = 0;
-        Storage* storage = frames[i]->document()->domWindow()->sessionStorage(ec);
+        Storage* storage = frame->document()->domWindow()->sessionStorage(ec);
         if (!ec)
-            frames[i]->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, storage));
+            frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, storage));
     }
 }
 
 void StorageEventDispatcher::dispatchLocalStorageEventsToFrames(PageGroup& pageGroup, const Vector<RefPtr<Frame>>& frames, const String& key, const String& oldValue, const String& newValue, const String& url, SecurityOrigin* securityOrigin)
 {
-    const HashSet<Page*>& pages = pageGroup.pages();
-    for (HashSet<Page*>::const_iterator it = pages.begin(), end = pages.end(); it != end; ++it)
-        InspectorInstrumentation::didDispatchDOMStorageEvent(key, oldValue, newValue, LocalStorage, securityOrigin, *it);
+    for (auto& page : pageGroup.pages())
+        InspectorInstrumentation::didDispatchDOMStorageEvent(key, oldValue, newValue, LocalStorage, securityOrigin, page);
 
-    for (unsigned i = 0; i < frames.size(); ++i) {
+    for (auto& frame : frames) {
         ExceptionCode ec = 0;
-        Storage* storage = frames[i]->document()->domWindow()->localStorage(ec);
+        Storage* storage = frame->document()->domWindow()->localStorage(ec);
         if (!ec)
-            frames[i]->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, storage));
+            frame->document()->enqueueWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, url, storage));
     }
 }
 
index 67b0acb..6eca29a 100644 (file)
@@ -184,9 +184,9 @@ bool StorageMap::contains(const String& key) const
 
 void StorageMap::importItems(const HashMap<String, String>& items)
 {
-    for (HashMap<String, String>::const_iterator it = items.begin(), end = items.end(); it != end; ++it) {
-        const String& key = it->key;
-        const String& value = it->value;
+    for (auto& item : items) {
+        const String& key = item.key;
+        const String& value = item.value;
 
         HashMap<String, String>::AddResult result = m_map.add(key, value);
         ASSERT_UNUSED(result, result.isNewEntry); // True if the key didn't exist previously.
index d814092..c60478b 100644 (file)
@@ -583,17 +583,16 @@ static bool pseudoStyleCacheIsInvalid(RenderElement* renderer, RenderStyle* newS
     if (!pseudoStyleCache)
         return false;
 
-    size_t cacheSize = pseudoStyleCache->size();
-    for (size_t i = 0; i < cacheSize; ++i) {
+    for (auto& cache : *pseudoStyleCache) {
         RefPtr<RenderStyle> newPseudoStyle;
-        PseudoId pseudoId = pseudoStyleCache->at(i)->styleType();
+        PseudoId pseudoId = cache->styleType();
         if (pseudoId == FIRST_LINE || pseudoId == FIRST_LINE_INHERITED)
             newPseudoStyle = renderer->uncachedFirstLineStyle(newStyle);
         else
             newPseudoStyle = renderer->getUncachedPseudoStyle(PseudoStyleRequest(pseudoId), newStyle, newStyle);
         if (!newPseudoStyle)
             return true;
-        if (*newPseudoStyle != *pseudoStyleCache->at(i)) {
+        if (*newPseudoStyle != *cache) {
             if (pseudoId < FIRST_INTERNAL_PSEUDOID)
                 newStyle->setHasPseudoStyle(pseudoId);
             newStyle->addCachedPseudoStyle(newPseudoStyle);
index 07f8cbd..5a22a17 100644 (file)
@@ -1383,8 +1383,8 @@ PassRefPtr<NodeList> Internals::nodesFromRect(Document* document, int centerX, i
         
         const HitTestResult::NodeSet& nodeSet = result.rectBasedTestResult();
         matches.reserveInitialCapacity(nodeSet.size());
-        for (auto it = nodeSet.begin(), end = nodeSet.end(); it != end; ++it)
-            matches.uncheckedAppend(*it->get());
+        for (auto& node : nodeSet)
+            matches.uncheckedAppend(*node);
     }
 
     return StaticNodeList::adopt(matches);
index ce0f651..d0c1d26 100644 (file)
@@ -54,9 +54,8 @@ static HashSet<Worker*>* allWorkers;
 
 void networkStateChanged(bool isOnLine)
 {
-    HashSet<Worker*>::iterator end = allWorkers->end();
-    for (HashSet<Worker*>::iterator it = allWorkers->begin(); it != end; ++it)
-        (*it)->notifyNetworkStateChange(isOnLine);
+    for (auto& worker : *allWorkers)
+        worker->notifyNetworkStateChange(isOnLine);
 }
 
 inline Worker::Worker(ScriptExecutionContext& context)
index 5bd8a1f..2a640d1 100644 (file)
@@ -175,21 +175,19 @@ void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionCode&
 {
     ASSERT(contentSecurityPolicy());
     ec = 0;
-    Vector<String>::const_iterator urlsEnd = urls.end();
     Vector<URL> completedURLs;
-    for (Vector<String>::const_iterator it = urls.begin(); it != urlsEnd; ++it) {
-        const URL& url = scriptExecutionContext()->completeURL(*it);
+    for (auto& entry : urls) {
+        URL url = scriptExecutionContext()->completeURL(entry);
         if (!url.isValid()) {
             ec = SYNTAX_ERR;
             return;
         }
-        completedURLs.append(url);
+        completedURLs.append(WTF::move(url));
     }
-    Vector<URL>::const_iterator end = completedURLs.end();
 
-    for (Vector<URL>::const_iterator it = completedURLs.begin(); it != end; ++it) {
+    for (auto& url : completedURLs) {
         Ref<WorkerScriptLoader> scriptLoader = WorkerScriptLoader::create();
-        scriptLoader->loadSynchronously(scriptExecutionContext(), *it, AllowCrossOriginRequests);
+        scriptLoader->loadSynchronously(scriptExecutionContext(), url, AllowCrossOriginRequests);
 
         // If the fetching attempt failed, throw a NETWORK_ERR exception and abort all these steps.
         if (scriptLoader->failed()) {