Avoid copy-prone idiom "for (auto item : collection)"
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Mar 2014 17:51:59 +0000 (17:51 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Mar 2014 17:51:59 +0000 (17:51 +0000)
commitfdf4aad20e780ffac7957fdd9e94198b719c8468
tree7db82fbbee204715f31f9c5df1aaa2ba7c767d7c
parentf7caba18dbe6ebd36db8b8c7dd89af875d873024
Avoid copy-prone idiom "for (auto item : collection)"
https://bugs.webkit.org/show_bug.cgi?id=129990

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

* heap/CodeBlockSet.h:
(JSC::CodeBlockSet::iterate): Use auto& to be sure we don't copy by accident.
* inspector/ScriptDebugServer.cpp:
(Inspector::ScriptDebugServer::dispatchBreakpointActionLog): Use auto* to
make explicit that we are iterating through pointers.
(Inspector::ScriptDebugServer::dispatchBreakpointActionSound): Ditto.
(Inspector::ScriptDebugServer::dispatchBreakpointActionProbe): Ditto.
* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::removeBreakpoint): Use auto&, and also
get rid of an unneeded local variable.

Source/WebCore:

Most of these changes have no effect. A few of them get rid of unwanted
copying of the items as we iterate them. Found these with the command
'git grep "for (auto .*:"' or the equivalent.

* Modules/indexeddb/IDBKeyData.cpp:
(WebCore::IDBKeyData::IDBKeyData): Use auto& to avoid copying the keys.
(WebCore::IDBKeyData::maybeCreateIDBKey): Ditto.
(WebCore::IDBKeyData::isolatedCopy): Ditto.

* dom/Node.cpp:
(WebCore::Document::invalidateNodeListAndCollectionCaches): Use auto*
to make explicit the fact that these are pointers. Stop using "it" for
a variable that is not an iterator. Get rid of unneeded local variables
for the collections themselves.

* dom/NodeRareData.h:
(WebCore::NodeListsNodeData::adoptDocument): Use auto& to make sure we
don't do any unnecessary copying. Stop using "it" for a variable that
is not an iterator.

* html/HTMLTableRowsCollection.cpp:
(WebCore::HTMLTableRowsCollection::lastRow): Use auto* to be explicit
that these are pointers.
* inspector/InspectorNodeFinder.cpp:
(WebCore::InspectorNodeFinder::searchUsingDOMTreeTraversal): Ditto.
* page/ios/FrameIOS.mm:
(WebCore::Frame::interpretationsForCurrentRoot): Ditto. Also got rid of
an unnecessary local variable.

* platform/FileChooser.cpp:
(WebCore::FileChooser::chooseFiles): Use auto&. Also fix a FIXME.
(WebCore::FileChooser::chooseMediaFiles): Ditto.

* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::naturalSize): Use auto&.

* rendering/RenderIterator.h: Changed include from RenderObject.h to
RenderElement.h; iterators are based on RenderElement now.

* rendering/svg/RenderSVGResource.cpp:
(WebCore::removeFromCacheAndInvalidateDependencies): Use auto*.

* rendering/svg/RenderSVGResourceContainer.cpp:
(WebCore::RenderSVGResourceContainer::markAllClientsForInvalidation): Use auto*.
(WebCore::RenderSVGResourceContainer::markAllClientLayersForInvalidation): Ditto.
(WebCore::RenderSVGResourceContainer::registerResource): Ditto.

* rendering/svg/SVGRenderSupport.cpp:
(WebCore::SVGRenderSupport::layoutChildren): Updated to use a more specific
type, to use auto* instead of of auto, and to eliminate the slightly sloppily
capitalized and not-so-slightly ungrammatical notlayoutedObjects.
(WebCore::SVGRenderSupport::applyStrokeStyleToContext): Use auto&.
(WebCore::SVGRenderSupport::updateMaskedAncestorShouldIsolateBlending): Use auto*.

* rendering/svg/SVGResourcesCycleSolver.cpp:
(WebCore::SVGResourcesCycleSolver::resourceContainsCycles): Use auto*.
(WebCore::SVGResourcesCycleSolver::resolveCycles): Ditto. Also lineageOfType.

* svg/SVGAnimateMotionElement.cpp:
(WebCore::SVGAnimateMotionElement::applyResultsToTarget): Use auto*.
* svg/SVGPathElement.cpp:
(WebCore::SVGPathElement::invalidateMPathDependencies): Ditto.

Source/WebKit/mac:

* WebView/WebFrame.mm:
(-[WebFrame _documentFragmentWithNodesAsParagraphs:]):
Use auto*. Also removed uneeded ASSERT_NO_EXCEPTION, which is already
the default without specifying it explicitly.

Source/WebKit2:

* Shared/mac/RemoteLayerTreePropertyApplier.mm:
(WebKit::RemoteLayerTreePropertyApplier::applyProperties): Use auto&.

* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::RemoteLayerTreeTransaction::LayerProperties::decode): Use auto&
even though the type is a scalar. This does no harm and makes it easier
to spot uses that trigger unnecessary copying with grep.
(WebKit::RemoteLayerTreeTransaction::decode): Ditto.
(WebKit::dumpChangedLayers): Ditto.
* UIProcess/mac/RemoteLayerTreeHost.mm:
(WebKit::RemoteLayerTreeHost::updateLayerTree): Ditto.
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::visitedLinkStateChanged): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@165546 268f45cc-cd09-0410-ab3c-d52691b4dbfc
27 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/CodeBlockSet.h
Source/JavaScriptCore/inspector/ScriptDebugServer.cpp
Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBKeyData.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/NodeRareData.h
Source/WebCore/html/HTMLTableRowsCollection.cpp
Source/WebCore/inspector/InspectorNodeFinder.cpp
Source/WebCore/page/ios/FrameIOS.mm
Source/WebCore/platform/FileChooser.cpp
Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm
Source/WebCore/rendering/RenderIterator.h
Source/WebCore/rendering/svg/RenderSVGResource.cpp
Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp
Source/WebCore/rendering/svg/SVGRenderSupport.cpp
Source/WebCore/rendering/svg/SVGResourcesCycleSolver.cpp
Source/WebCore/svg/SVGAnimateMotionElement.cpp
Source/WebCore/svg/SVGPathElement.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebFrame.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/mac/RemoteLayerTreePropertyApplier.mm
Source/WebKit2/Shared/mac/RemoteLayerTreeTransaction.mm
Source/WebKit2/UIProcess/mac/RemoteLayerTreeHost.mm
Source/WebKit2/WebProcess/WebProcess.cpp