Correct some uses of 'auto'
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Feb 2014 17:36:07 +0000 (17:36 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Feb 2014 17:36:07 +0000 (17:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128578

Reviewed by Anders Carlsson.

Correct the following instances of "for (auto ...)" to use reference or
const references to avoid copies.

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::elementsFromAttribute):
* css/CSSGridTemplateValue.cpp:
(WebCore::stringForPosition):
* dom/Node.cpp:
(WebCore::NodeListsNodeData::invalidateCaches):
* inspector/PageInjectedScriptManager.cpp:
(WebCore::PageInjectedScriptManager::discardInjectedScriptsFor):
* page/WheelEventDeltaTracker.cpp:
(WebCore::WheelEventDeltaTracker::dominantScrollGestureDirection):
* page/scrolling/ScrollingCoordinator.cpp:
(WebCore::ScrollingCoordinator::computeNonFastScrollableRegion):
* platform/graphics/mac/WebLayer.mm:
(WebCore::drawLayerContents):
* platform/ios/TileGrid.mm:
(WebCore::TileGrid::dropTilesBetweenRects):
(WebCore::TileGrid::dropDistantTiles):
(WebCore::TileGrid::dropInvalidTiles):
* rendering/InlineTextBox.cpp:
(WebCore::translateIntersectionPointsToSkipInkBoundaries):
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::Backup::restoreTo):

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

Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/css/CSSGridTemplateValue.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/inspector/PageInjectedScriptManager.cpp
Source/WebCore/page/WheelEventDeltaTracker.cpp
Source/WebCore/page/scrolling/ScrollingCoordinator.cpp
Source/WebCore/platform/graphics/mac/WebLayer.mm
Source/WebCore/platform/ios/TileGrid.mm
Source/WebCore/rendering/InlineTextBox.cpp
Source/WebCore/testing/InternalSettings.cpp

index ef361c2..de092dc 100644 (file)
@@ -1,3 +1,36 @@
+2014-02-11  Brent Fulgham  <bfulgham@apple.com>
+
+        Correct some uses of 'auto'
+        https://bugs.webkit.org/show_bug.cgi?id=128578
+
+        Reviewed by Anders Carlsson.
+
+        Correct the following instances of "for (auto ...)" to use reference or
+        const references to avoid copies.
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::elementsFromAttribute):
+        * css/CSSGridTemplateValue.cpp:
+        (WebCore::stringForPosition):
+        * dom/Node.cpp:
+        (WebCore::NodeListsNodeData::invalidateCaches):
+        * inspector/PageInjectedScriptManager.cpp:
+        (WebCore::PageInjectedScriptManager::discardInjectedScriptsFor):
+        * page/WheelEventDeltaTracker.cpp:
+        (WebCore::WheelEventDeltaTracker::dominantScrollGestureDirection):
+        * page/scrolling/ScrollingCoordinator.cpp:
+        (WebCore::ScrollingCoordinator::computeNonFastScrollableRegion):
+        * platform/graphics/mac/WebLayer.mm:
+        (WebCore::drawLayerContents):
+        * platform/ios/TileGrid.mm:
+        (WebCore::TileGrid::dropTilesBetweenRects):
+        (WebCore::TileGrid::dropDistantTiles):
+        (WebCore::TileGrid::dropInvalidTiles):
+        * rendering/InlineTextBox.cpp:
+        (WebCore::translateIntersectionPointsToSkipInkBoundaries):
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::Backup::restoreTo):
+
 2014-02-10  David Hyatt  <hyatt@apple.com>
 
         [New Multicolumn] Make columns work with line grids
index 8b943ae..fca7c9f 100644 (file)
@@ -2265,7 +2265,7 @@ void AccessibilityObject::elementsFromAttribute(Vector<Element*>& elements, cons
     Vector<String> idVector;
     idList.split(' ', idVector);
 
-    for (auto idName : idVector) {
+    for (const auto& idName : idVector) {
         if (Element* idElement = treeScope.getElementById(idName))
             elements.append(idElement);
     }
index 5fa8ef5..0f2e1ac 100644 (file)
@@ -51,16 +51,16 @@ static String stringForPosition(const NamedGridAreaMap& gridAreaMap, size_t row,
 {
     Vector<String> candidates;
 
-    for (auto it = gridAreaMap.begin(), end = gridAreaMap.end(); it != end; ++it) {
-        const GridCoordinate& coordinate = it->value;
+    for (const auto& it : gridAreaMap) {
+        const GridCoordinate& coordinate = it.value;
         if (row >= coordinate.rows.initialPositionIndex && row <= coordinate.rows.finalPositionIndex)
-            candidates.append(it->key);
+            candidates.append(it.key);
     }
 
-    for (auto it = gridAreaMap.begin(), end = gridAreaMap.end(); it != end; ++it) {
-        const GridCoordinate& coordinate = it->value;
-        if (column >= coordinate.columns.initialPositionIndex && column <= coordinate.columns.finalPositionIndex && candidates.contains(it->key))
-            return it->key;
+    for (const auto& it : gridAreaMap) {
+        const GridCoordinate& coordinate = it.value;
+        if (column >= coordinate.columns.initialPositionIndex && column <= coordinate.columns.finalPositionIndex && candidates.contains(it.key))
+            return it.key;
     }
 
     return ".";
index 45ac323..72f8a84 100644 (file)
@@ -1694,20 +1694,20 @@ void Node::showTreeForThisAcrossFrame() const
 
 void NodeListsNodeData::invalidateCaches(const QualifiedName* attrName)
 {
-    for (auto it = m_atomicNameCaches.begin(), end = m_atomicNameCaches.end(); it != end; ++it)
-        it->value->invalidateCache(attrName);
+    for (auto& atomicName : m_atomicNameCaches)
+        atomicName.value->invalidateCache(attrName);
 
-    for (auto it = m_nameCaches.begin(), end = m_nameCaches.end(); it != end; ++it)
-        it->value->invalidateCache(attrName);
+    for (auto& name : m_nameCaches)
+        name.value->invalidateCache(attrName);
 
-    for (auto it = m_cachedCollections.begin(), end = m_cachedCollections.end(); it != end; ++it)
-        it->value->invalidateCache(attrName);
+    for (auto& collection : m_cachedCollections)
+        collection.value->invalidateCache(attrName);
 
     if (attrName)
         return;
 
-    for (auto it = m_tagNodeListCacheNS.begin(), end = m_tagNodeListCacheNS.end(); it != end; ++it)
-        it->value->invalidateCache();
+    for (auto& tagNodeList : m_tagNodeListCacheNS)
+        tagNodeList.value->invalidateCache();
 }
 
 void Node::getSubresourceURLs(ListHashSet<URL>& urls) const
index 60c66f7..6a62ea1 100644 (file)
@@ -60,12 +60,12 @@ void PageInjectedScriptManager::discardInjectedScriptsFor(DOMWindow* window)
         return;
 
     Vector<long> idsToRemove;
-    for (auto it = m_idToInjectedScript.begin(), end = m_idToInjectedScript.end(); it != end; ++it) {
-        JSC::ExecState* scriptState = it->value.scriptState();
+    for (const auto& it : m_idToInjectedScript) {
+        JSC::ExecState* scriptState = it.value.scriptState();
         if (window != domWindowFromExecState(scriptState))
             continue;
         m_scriptStateToId.remove(scriptState);
-        idsToRemove.append(it->key);
+        idsToRemove.append(it.key);
     }
 
     for (size_t i = 0; i < idsToRemove.size(); i++)
@@ -73,8 +73,8 @@ void PageInjectedScriptManager::discardInjectedScriptsFor(DOMWindow* window)
 
     // Now remove script states that have id but no injected script.
     Vector<JSC::ExecState*> scriptStatesToRemove;
-    for (auto it = m_scriptStateToId.begin(), end = m_scriptStateToId.end(); it != end; ++it) {
-        JSC::ExecState* scriptState = it->key;
+    for (const auto& it : m_scriptStateToId) {
+        JSC::ExecState* scriptState = it.key;
         if (window == domWindowFromExecState(scriptState))
             scriptStatesToRemove.append(scriptState);
     }
index d410646..3ed9993 100644 (file)
@@ -68,9 +68,8 @@ DominantScrollGestureDirection WheelEventDeltaTracker::dominantScrollGestureDire
     bool allVertical = m_recentWheelEventDeltas.size();
     bool allHorizontal = m_recentWheelEventDeltas.size();
 
-    auto end = m_recentWheelEventDeltas.end();
-    for (auto it = m_recentWheelEventDeltas.begin(); it != end; ++it) {
-        bool isVertical = deltaIsPredominantlyVertical(*it);
+    for (const auto& delta : m_recentWheelEventDeltas) {
+        bool isVertical = deltaIsPredominantlyVertical(delta);
         allVertical &= isVertical;
         allHorizontal &= !isVertical;
     }
index 0749c84..8dad160 100644 (file)
@@ -107,7 +107,7 @@ Region ScrollingCoordinator::computeNonFastScrollableRegion(const Frame* frame,
     document->getTouchRects(touchRects);
     
     Region touchRegion;
-    for (auto rect : touchRects)
+    for (const auto& rect : touchRects)
         touchRegion.unite(rect);
 
     return touchRegion;
@@ -132,10 +132,10 @@ Region ScrollingCoordinator::computeNonFastScrollableRegion(const Frame* frame,
         }
     }
 
-    for (auto it = frameView->children().begin(), end = frameView->children().end(); it != end; ++it) {
-        if (!(*it)->isPluginViewBase())
+    for (const auto& child : frameView->children()) {
+        if (!child->isPluginViewBase())
             continue;
-        PluginViewBase* pluginViewBase = toPluginViewBase((*it).get());
+        PluginViewBase* pluginViewBase = toPluginViewBase(child.get());
         if (pluginViewBase->wantsWheelEvents())
             nonFastScrollableRegion.unite(pluginViewBase->frameRect());
     }
index 9f2179d..e8b8a4c 100644 (file)
@@ -130,7 +130,7 @@ void drawLayerContents(CGContextRef context, WebCore::PlatformCALayer* platformC
     ThemeMac::setFocusRingClipRect(focusRingClipRect);
 #endif // !PLATFORM(IOS)
 
-    for (auto rect : dirtyRects) {
+    for (const auto& rect : dirtyRects) {
         GraphicsContextStateSaver stateSaver(graphicsContext);
         graphicsContext.clip(rect);
 
index 2d9c6ac..e623fa5 100644 (file)
@@ -85,7 +85,7 @@ void TileGrid::dropTilesOutsideRect(const IntRect& keepRect)
 void TileGrid::dropTilesBetweenRects(const IntRect& dropRect, const IntRect& keepRect)
 {
     Vector<TileIndex> toRemove;
-    for (auto tile : m_tiles) {
+    for (const auto& tile : m_tiles) {
         TileIndex& index = tile.key;
         IntRect tileRect = tile.value->rect();
         if (tileRect.intersects(dropRect) && !tileRect.intersects(keepRect))
@@ -124,9 +124,9 @@ bool TileGrid::dropDistantTiles(unsigned tilesNeeded, double shortestDistance)
 
     IntRect visibleRect = this->visibleRect();
     Vector<std::pair<double, TileIndex>> toRemove;
-    for (auto tile : m_tiles) {
+    for (const auto& tile : m_tiles) {
         TileIndex& index = tile.key;
-        IntRect tileRect = tile.value->rect();
+        const IntRect& tileRect = tile.value->rect();
         double distance = tileDistance2(visibleRect, tileRect);
         if (distance <= shortestDistance)
             continue;
@@ -316,9 +316,9 @@ void TileGrid::dropInvalidTiles()
     IntRect bounds = this->bounds();
     IntRect dropBounds = intersection(m_validBounds, bounds);
     Vector<TileIndex> toRemove;
-    for (auto tile : m_tiles) {
+    for (const auto& tile : m_tiles) {
         TileIndex& index = tile.key;
-        IntRect tileRect = tile.value->rect();
+        const IntRect& tileRect = tile.value->rect();
         IntRect expectedTileRect = tileRectForIndex(index);
         if (expectedTileRect != tileRect || !dropBounds.contains(tileRect))
             toRemove.append(index);
index 3fbcad1..d6f8a3b 100644 (file)
@@ -103,12 +103,12 @@ static DashArray translateIntersectionPointsToSkipInkBoundaries(const DashArray&
     // Step 3: Output the space between the ranges, but only if the space warrants an underline.
     float previous = 0;
     DashArray result;
-    for (auto i = intermediateTuples.begin(); i != intermediateTuples.end(); i++) {
-        if (i->first - previous > dilationAmount) {
+    for (const auto& tuple : intermediateTuples) {
+        if (tuple.first - previous > dilationAmount) {
             result.append(previous);
-            result.append(i->first);
+            result.append(tuple.first);
         }
-        previous = i->second;
+        previous = tuple.second;
     }
     if (totalWidth - previous > dilationAmount) {
         result.append(previous);
index dc7da1e..54310d2 100644 (file)
@@ -107,32 +107,32 @@ void InternalSettings::Backup::restoreTo(Settings& settings)
 #endif
     settings.setEditingBehaviorType(m_originalEditingBehavior);
 
-    for (auto iter = m_standardFontFamilies.begin(); iter != m_standardFontFamilies.end(); ++iter)
-        settings.setStandardFontFamily(iter->value, static_cast<UScriptCode>(iter->key));
+    for (const auto& standardFont : m_standardFontFamilies)
+        settings.setStandardFontFamily(standardFont.value, static_cast<UScriptCode>(standardFont.key));
     m_standardFontFamilies.clear();
 
-    for (auto iter = m_fixedFontFamilies.begin(); iter != m_fixedFontFamilies.end(); ++iter)
-        settings.setFixedFontFamily(iter->value, static_cast<UScriptCode>(iter->key));
+    for (const auto& fixedFont : m_fixedFontFamilies)
+        settings.setFixedFontFamily(fixedFont.value, static_cast<UScriptCode>(fixedFont.key));
     m_fixedFontFamilies.clear();
 
-    for (auto iter = m_serifFontFamilies.begin(); iter != m_serifFontFamilies.end(); ++iter)
-        settings.setSerifFontFamily(iter->value, static_cast<UScriptCode>(iter->key));
+    for (const auto& serifFont : m_serifFontFamilies)
+        settings.setSerifFontFamily(serifFont.value, static_cast<UScriptCode>(serifFont.key));
     m_serifFontFamilies.clear();
 
-    for (auto iter = m_sansSerifFontFamilies.begin(); iter != m_sansSerifFontFamilies.end(); ++iter)
-        settings.setSansSerifFontFamily(iter->value, static_cast<UScriptCode>(iter->key));
+    for (const auto& sansSerifFont : m_sansSerifFontFamilies)
+        settings.setSansSerifFontFamily(sansSerifFont.value, static_cast<UScriptCode>(sansSerifFont.key));
     m_sansSerifFontFamilies.clear();
 
-    for (auto iter = m_cursiveFontFamilies.begin(); iter != m_cursiveFontFamilies.end(); ++iter)
-        settings.setCursiveFontFamily(iter->value, static_cast<UScriptCode>(iter->key));
+    for (const auto& cursiveFont : m_cursiveFontFamilies)
+        settings.setCursiveFontFamily(cursiveFont.value, static_cast<UScriptCode>(cursiveFont.key));
     m_cursiveFontFamilies.clear();
 
-    for (auto iter = m_fantasyFontFamilies.begin(); iter != m_fantasyFontFamilies.end(); ++iter)
-        settings.setFantasyFontFamily(iter->value, static_cast<UScriptCode>(iter->key));
+    for (const auto& fantasyFont : m_fantasyFontFamilies)
+        settings.setFantasyFontFamily(fantasyFont.value, static_cast<UScriptCode>(fantasyFont.key));
     m_fantasyFontFamilies.clear();
 
-    for (auto iter = m_pictographFontFamilies.begin(); iter != m_pictographFontFamilies.end(); ++iter)
-        settings.setPictographFontFamily(iter->value, static_cast<UScriptCode>(iter->key));
+    for (const auto& pictographFont : m_pictographFontFamilies)
+        settings.setPictographFontFamily(pictographFont.value, static_cast<UScriptCode>(pictographFont.key));
     m_pictographFontFamilies.clear();
 
 #if ENABLE(TEXT_AUTOSIZING)