clang-tidy: Fix unnecessary copy/ref churn of for loop variables in WTF/JavaScriptCore
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Sep 2019 11:39:57 +0000 (11:39 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Sep 2019 11:39:57 +0000 (11:39 +0000)
<https://webkit.org/b/202069>

Reviewed by Mark Lam.

Fix unwanted copying/ref churn of loop variables by making them
const references.

Source/JavaScriptCore:

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::setConstantIdentifierSetRegisters):
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::prepareLexicalScopeForNextForLoopIteration):
* dfg/DFGGraph.cpp:
(JSC::DFG::Graph::dump):
* inspector/agents/InspectorAgent.cpp:
(Inspector::InspectorAgent::activateExtraDomains):
* inspector/remote/cocoa/RemoteInspectorCocoa.mm:
(Inspector::RemoteInspector::stopInternal):
(Inspector::RemoteInspector::xpcConnectionFailed):
(Inspector::RemoteInspector::pushListingsNow):
* parser/Parser.h:
(JSC::Scope::computeLexicallyCapturedVariablesAndPurgeCandidates):
* runtime/ProxyObject.cpp:
(JSC::ProxyObject::performGetOwnPropertyNames):
* runtime/SamplingProfiler.cpp:
(JSC::SamplingProfiler::registerForReportAtExit):
(JSC::SamplingProfiler::reportTopFunctions):
(JSC::SamplingProfiler::reportTopBytecodes):
* runtime/TypeSet.cpp:
(JSC::StructureShape::inspectorRepresentation):
(JSC::StructureShape::merge):

Source/WTF:

* wtf/AggregateLogger.h:
(WTF::AggregateLogger::log const):

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

12 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/CodeBlock.cpp
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
Source/JavaScriptCore/dfg/DFGGraph.cpp
Source/JavaScriptCore/inspector/agents/InspectorAgent.cpp
Source/JavaScriptCore/inspector/remote/cocoa/RemoteInspectorCocoa.mm
Source/JavaScriptCore/parser/Parser.h
Source/JavaScriptCore/runtime/ProxyObject.cpp
Source/JavaScriptCore/runtime/SamplingProfiler.cpp
Source/JavaScriptCore/runtime/TypeSet.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/AggregateLogger.h

index 10ea1c4..2fb40cd 100644 (file)
@@ -1,3 +1,37 @@
+2019-09-21  David Kilzer  <ddkilzer@apple.com>
+
+        clang-tidy: Fix unnecessary copy/ref churn of for loop variables in WTF/JavaScriptCore
+        <https://webkit.org/b/202069>
+
+        Reviewed by Mark Lam.
+
+        Fix unwanted copying/ref churn of loop variables by making them
+        const references.
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::setConstantIdentifierSetRegisters):
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::prepareLexicalScopeForNextForLoopIteration):
+        * dfg/DFGGraph.cpp:
+        (JSC::DFG::Graph::dump):
+        * inspector/agents/InspectorAgent.cpp:
+        (Inspector::InspectorAgent::activateExtraDomains):
+        * inspector/remote/cocoa/RemoteInspectorCocoa.mm:
+        (Inspector::RemoteInspector::stopInternal):
+        (Inspector::RemoteInspector::xpcConnectionFailed):
+        (Inspector::RemoteInspector::pushListingsNow):
+        * parser/Parser.h:
+        (JSC::Scope::computeLexicallyCapturedVariablesAndPurgeCandidates):
+        * runtime/ProxyObject.cpp:
+        (JSC::ProxyObject::performGetOwnPropertyNames):
+        * runtime/SamplingProfiler.cpp:
+        (JSC::SamplingProfiler::registerForReportAtExit):
+        (JSC::SamplingProfiler::reportTopFunctions):
+        (JSC::SamplingProfiler::reportTopBytecodes):
+        * runtime/TypeSet.cpp:
+        (JSC::StructureShape::inspectorRepresentation):
+        (JSC::StructureShape::merge):
+
 2019-09-20  Keith Miller  <keith_miller@apple.com>
 
         eliding a move in Air O0 needs to mark the dest's old reg as available
index 5b4ab15..b790947 100644 (file)
@@ -882,7 +882,7 @@ void CodeBlock::setConstantIdentifierSetRegisters(VM& vm, const Vector<ConstantI
         JSSet* jsSet = JSSet::create(exec, vm, setStructure, set.size());
         RETURN_IF_EXCEPTION(scope, void());
 
-        for (auto setEntry : set) {
+        for (const auto& setEntry : set) {
             JSString* jsString = jsOwnedString(vm, setEntry.get()); 
             jsSet->add(exec, jsString);
             RETURN_IF_EXCEPTION(scope, void());
index fb47b5e..32e4086 100644 (file)
@@ -2326,7 +2326,7 @@ void BytecodeGenerator::prepareLexicalScopeForNextForLoopIteration(VariableEnvir
     move(scopeRegister(), loopScope);
 
     {
-        for (auto pair : activationValuesToCopyOver) {
+        for (const auto& pair : activationValuesToCopyOver) {
             const Identifier& identifier = pair.second;
             SymbolTableEntry entry = symbolTable->get(NoLockingNecessary, identifier.impl());
             RELEASE_ASSERT(!entry.isNull());
index a594cf0..9d5b7d9 100644 (file)
@@ -546,7 +546,7 @@ void Graph::dump(PrintStream& out, DumpContext* context)
             out.print(prefix, "  Argument formats for entrypoint index: ", entrypointIndex, " : ", listDump(m_argumentFormats[entrypointIndex]), "\n");
     }
     else {
-        for (auto pair : m_rootToArguments)
+        for (const auto& pair : m_rootToArguments)
             out.print(prefix, "  Arguments for block#", pair.key->index, ": ", listDump(pair.value), "\n");
     }
     out.print("\n");
index 1ca3804..1c5e29a 100644 (file)
@@ -120,7 +120,7 @@ void InspectorAgent::activateExtraDomains(const Vector<String>& extraDomains)
         return;
 
     auto domainNames = JSON::ArrayOf<String>::create();
-    for (auto domainName : extraDomains)
+    for (const auto& domainName : extraDomains)
         domainNames->addItem(domainName);
 
     m_frontendDispatcher->activateExtraDomains(WTFMove(domainNames));
index 665266b..2bb96ec 100644 (file)
@@ -239,7 +239,7 @@ void RemoteInspector::stopInternal(StopSource source)
 
     m_pushScheduled = false;
 
-    for (auto targetConnection : m_targetConnectionMap.values())
+    for (const auto& targetConnection : m_targetConnectionMap.values())
         targetConnection->close();
     m_targetConnectionMap.clear();
 
@@ -347,7 +347,7 @@ void RemoteInspector::xpcConnectionFailed(RemoteInspectorXPCConnection* relayCon
 
     m_pushScheduled = false;
 
-    for (auto targetConnection : m_targetConnectionMap.values())
+    for (const auto& targetConnection : m_targetConnectionMap.values())
         targetConnection->close();
     m_targetConnectionMap.clear();
 
@@ -437,7 +437,7 @@ void RemoteInspector::pushListingsNow()
     m_pushScheduled = false;
 
     RetainPtr<NSMutableDictionary> listings = adoptNS([[NSMutableDictionary alloc] init]);
-    for (RetainPtr<NSDictionary> listing : m_targetListingMap.values()) {
+    for (const auto& listing : m_targetListingMap.values()) {
         NSString *targetIdentifierString = [[listing.get() objectForKey:WIRTargetIdentifierKey] stringValue];
         [listings setObject:listing.get() forKey:targetIdentifierString];
     }
index 296a9b5..c89b00d 100644 (file)
@@ -330,7 +330,7 @@ public:
 
         // We can now purge values from the captured candidates because they're captured in this scope.
         {
-            for (auto entry : m_lexicalVariables) {
+            for (const auto& entry : m_lexicalVariables) {
                 if (entry.value.isCaptured())
                     m_closedVariableCandidates.remove(entry.key.get());
             }
index 3de76ab..9f95c02 100644 (file)
@@ -1056,7 +1056,7 @@ void ProxyObject::performGetOwnPropertyNames(ExecState* exec, PropertyNameArray&
 
     if (!enumerationMode.includeDontEnumProperties()) {
         // Filtering DontEnum properties is observable in proxies and must occur following the invariant checks above.
-        for (auto propertyName : trapResult) {
+        for (const auto& propertyName : trapResult) {
             PropertySlot slot(this, PropertySlot::InternalMethodType::GetOwnProperty);
             auto result = getOwnPropertySlotCommon(exec, propertyName, slot);
             RETURN_IF_EXCEPTION(scope, void());
@@ -1067,7 +1067,7 @@ void ProxyObject::performGetOwnPropertyNames(ExecState* exec, PropertyNameArray&
             propertyNames.add(propertyName.impl());
         }
     } else {
-        for (auto propertyName : trapResult)
+        for (const auto& propertyName : trapResult)
             propertyNames.add(propertyName.impl());
     }
 }
index ac465b2..082021a 100644 (file)
@@ -1013,7 +1013,7 @@ void SamplingProfiler::registerForReportAtExit()
     if (!profilesToReport) {
         profilesToReport = new HashSet<RefPtr<SamplingProfiler>>();
         atexit([]() {
-            for (auto profile : *profilesToReport)
+            for (const auto& profile : *profilesToReport)
                 profile->reportDataToOptionFile();
         });
     }
@@ -1066,7 +1066,7 @@ void SamplingProfiler::reportTopFunctions(PrintStream& out)
     auto takeMax = [&] () -> std::pair<String, size_t> {
         String maxFrameDescription;
         size_t maxFrameCount = 0;
-        for (auto entry : functionCounts) {
+        for (const auto& entry : functionCounts) {
             if (entry.value > maxFrameCount) {
                 maxFrameCount = entry.value;
                 maxFrameDescription = entry.key;
@@ -1146,7 +1146,7 @@ void SamplingProfiler::reportTopBytecodes(PrintStream& out)
     auto takeMax = [&] () -> std::pair<String, size_t> {
         String maxFrameDescription;
         size_t maxFrameCount = 0;
-        for (auto entry : bytecodeCounts) {
+        for (const auto& entry : bytecodeCounts) {
             if (entry.value > maxFrameCount) {
                 maxFrameCount = entry.value;
                 maxFrameDescription = entry.key;
index b9d0ffd..9db1d88 100644 (file)
@@ -497,9 +497,9 @@ Ref<Inspector::Protocol::Runtime::StructureDescription> StructureShape::inspecto
     while (currentShape) {
         auto fields = JSON::ArrayOf<String>::create();
         auto optionalFields = JSON::ArrayOf<String>::create();
-        for (auto field : currentShape->m_fields)
+        for (const auto& field : currentShape->m_fields)
             fields->addItem(field.get());
-        for (auto field : currentShape->m_optionalFields)
+        for (const auto& field : currentShape->m_optionalFields)
             optionalFields->addItem(field.get());
 
         currentObject->setFields(&fields.get());
@@ -538,23 +538,23 @@ Ref<StructureShape> StructureShape::merge(Ref<StructureShape>&& a, Ref<Structure
     ASSERT(a->hasSamePrototypeChain(b.get()));
 
     auto merged = StructureShape::create();
-    for (auto field : a->m_fields) {
+    for (const auto& field : a->m_fields) {
         if (b->m_fields.contains(field))
             merged->m_fields.add(field);
         else
             merged->m_optionalFields.add(field);
     }
 
-    for (auto field : b->m_fields) {
+    for (const auto& field : b->m_fields) {
         if (!merged->m_fields.contains(field)) {
             auto addResult = merged->m_optionalFields.add(field);
             ASSERT_UNUSED(addResult, addResult.isNewEntry);
         }
     }
 
-    for (auto field : a->m_optionalFields)
+    for (const auto& field : a->m_optionalFields)
         merged->m_optionalFields.add(field);
-    for (auto field : b->m_optionalFields)
+    for (const auto& field : b->m_optionalFields)
         merged->m_optionalFields.add(field);
 
     ASSERT(a->m_constructorName == b->m_constructorName);
index 9361590..5d80734 100644 (file)
@@ -1,3 +1,16 @@
+2019-09-21  David Kilzer  <ddkilzer@apple.com>
+
+        clang-tidy: Fix unnecessary copy/ref churn of for loop variables in WTF/JavaScriptCore
+        <https://webkit.org/b/202069>
+
+        Reviewed by Mark Lam.
+
+        Fix unwanted copying/ref churn of loop variables by making them
+        const references.
+
+        * wtf/AggregateLogger.h:
+        (WTF::AggregateLogger::log const):
+
 2019-09-20  Keith Rollin  <krollin@apple.com>
 
         Remove some support for < iOS 13
index dd7a199..a04752a 100644 (file)
@@ -104,7 +104,7 @@ private:
 
         Logger::log(channel, level, arguments...);
 
-        for (auto logger : m_loggers) {
+        for (const auto& logger : m_loggers) {
             for (Observer& observer : logger->observers())
                 observer.didLogMessage(channel, level, { ConsoleLogValue<Argument>::toValue(arguments)... });
         }