Modernize for loops in JSC
authorannulen@yandex.ru <annulen@yandex.ru@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Dec 2016 18:26:10 +0000 (18:26 +0000)
committerannulen@yandex.ru <annulen@yandex.ru@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Dec 2016 18:26:10 +0000 (18:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166060

Reviewed by Yusuke Suzuki.

* API/JSCallbackObject.h:
(JSC::JSCallbackObjectData::JSPrivatePropertyMap::visitChildren):
* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::dumpBytecode):
(JSC::CodeBlock::propagateTransitions):
(JSC::CodeBlock::stronglyVisitStrongReferences):
(JSC::CodeBlock::stronglyVisitWeakReferences):
(JSC::CodeBlock::jettison):
(JSC::CodeBlock::getArrayProfile):
(JSC::CodeBlock::tallyFrequentExitSites):
(JSC::CodeBlock::nameForRegister):
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::generate):
(JSC::BytecodeGenerator::BytecodeGenerator):
* bytecompiler/NodesCodegen.cpp:
(JSC::ObjectPatternNode::bindValue):
* debugger/Debugger.cpp:
(JSC::Debugger::applyBreakpoints):
* dfg/DFGCPSRethreadingPhase.cpp:
(JSC::DFG::CPSRethreadingPhase::canonicalizeLocalsInBlock):
* dfg/DFGClobberSet.cpp:
(JSC::DFG::ClobberSet::setOf):
* dfg/DFGDesiredIdentifiers.cpp:
(JSC::DFG::DesiredIdentifiers::reallyAdd):
* dfg/DFGGraph.cpp:
(JSC::DFG::Graph::visitChildren):
* dfg/DFGIntegerCheckCombiningPhase.cpp:
(JSC::DFG::IntegerCheckCombiningPhase::handleBlock):
* dfg/DFGIntegerRangeOptimizationPhase.cpp:
* dfg/DFGJITCompiler.cpp:
(JSC::DFG::JITCompiler::link):
* dfg/DFGLICMPhase.cpp:
(JSC::DFG::LICMPhase::run):
* dfg/DFGMaximalFlushInsertionPhase.cpp:
(JSC::DFG::MaximalFlushInsertionPhase::treatRootBlock):
* dfg/DFGPutStackSinkingPhase.cpp:
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileCurrentBlock):
(JSC::DFG::SpeculativeJIT::linkBranches):
* dfg/DFGStructureRegistrationPhase.cpp:
(JSC::DFG::StructureRegistrationPhase::run):
* dfg/DFGTypeCheckHoistingPhase.cpp:
(JSC::DFG::TypeCheckHoistingPhase::identifyRedundantStructureChecks):
(JSC::DFG::TypeCheckHoistingPhase::identifyRedundantArrayChecks):
* dfg/DFGValidate.cpp:
* dfg/DFGVirtualRegisterAllocationPhase.cpp:
(JSC::DFG::VirtualRegisterAllocationPhase::run):
* heap/HeapVerifier.cpp:
(JSC::trimDeadObjectsFromList):
(JSC::HeapVerifier::trimDeadObjects):
* heap/LiveObjectList.cpp:
(JSC::LiveObjectList::findObject):
* heap/MarkedAllocator.cpp:
(JSC::MarkedAllocator::isPagedOut):
* inspector/ScriptCallStack.cpp:
(Inspector::ScriptCallStack::firstNonNativeCallFrame):
* jit/JIT.cpp:
(JSC::JIT::link):
* parser/VariableEnvironment.cpp:
(JSC::VariableEnvironment::markAllVariablesAsCaptured):
(JSC::VariableEnvironment::hasCapturedVariables):
* runtime/FunctionHasExecutedCache.cpp:
(JSC::FunctionHasExecutedCache::hasExecutedAtOffset):
(JSC::FunctionHasExecutedCache::getFunctionRanges):
* runtime/JSPropertyNameEnumerator.cpp:
(JSC::JSPropertyNameEnumerator::visitChildren):
* runtime/TypeProfiler.cpp:
(JSC::TypeProfiler::findLocation):
* runtime/TypeSet.cpp:
(JSC::TypeSet::addTypeInformation):
(JSC::TypeSet::dumpTypes):
* runtime/VM.cpp:
(JSC::VM::gatherConservativeRoots):
* runtime/WeakMapData.cpp:
(JSC::WeakMapData::DeadKeyCleaner::visitWeakReferences):
(JSC::WeakMapData::DeadKeyCleaner::finalizeUnconditionally):
* tools/ProfileTreeNode.h:
(JSC::ProfileTreeNode::dumpInternal):
* yarr/YarrInterpreter.cpp:
(JSC::Yarr::ByteCompiler::emitDisjunction):

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

35 files changed:
Source/JavaScriptCore/API/JSCallbackObject.h
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/CodeBlock.cpp
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Source/JavaScriptCore/debugger/Debugger.cpp
Source/JavaScriptCore/dfg/DFGCPSRethreadingPhase.cpp
Source/JavaScriptCore/dfg/DFGClobberSet.cpp
Source/JavaScriptCore/dfg/DFGDesiredIdentifiers.cpp
Source/JavaScriptCore/dfg/DFGGraph.cpp
Source/JavaScriptCore/dfg/DFGIntegerCheckCombiningPhase.cpp
Source/JavaScriptCore/dfg/DFGIntegerRangeOptimizationPhase.cpp
Source/JavaScriptCore/dfg/DFGJITCompiler.cpp
Source/JavaScriptCore/dfg/DFGLICMPhase.cpp
Source/JavaScriptCore/dfg/DFGMaximalFlushInsertionPhase.cpp
Source/JavaScriptCore/dfg/DFGPutStackSinkingPhase.cpp
Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp
Source/JavaScriptCore/dfg/DFGStructureRegistrationPhase.cpp
Source/JavaScriptCore/dfg/DFGTypeCheckHoistingPhase.cpp
Source/JavaScriptCore/dfg/DFGValidate.cpp
Source/JavaScriptCore/dfg/DFGVirtualRegisterAllocationPhase.cpp
Source/JavaScriptCore/heap/HeapVerifier.cpp
Source/JavaScriptCore/heap/LiveObjectList.cpp
Source/JavaScriptCore/heap/MarkedAllocator.cpp
Source/JavaScriptCore/inspector/ScriptCallStack.cpp
Source/JavaScriptCore/jit/JIT.cpp
Source/JavaScriptCore/parser/VariableEnvironment.cpp
Source/JavaScriptCore/runtime/FunctionHasExecutedCache.cpp
Source/JavaScriptCore/runtime/JSPropertyNameEnumerator.cpp
Source/JavaScriptCore/runtime/TypeProfiler.cpp
Source/JavaScriptCore/runtime/TypeSet.cpp
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/WeakMapData.cpp
Source/JavaScriptCore/tools/ProfileTreeNode.h
Source/JavaScriptCore/yarr/YarrInterpreter.cpp

index f615ce9..31f2166 100644 (file)
@@ -106,9 +106,9 @@ public:
         void visitChildren(SlotVisitor& visitor)
         {
             LockHolder locker(m_lock);
-            for (PrivatePropertyMap::iterator ptr = m_propertyMap.begin(); ptr != m_propertyMap.end(); ++ptr) {
-                if (ptr->value)
-                    visitor.append(ptr->value);
+            for (auto& pair : m_propertyMap) {
+                if (pair.value)
+                    visitor.append(pair.value);
             }
         }
 
index facf91c..004fdd9 100644 (file)
@@ -1,5 +1,93 @@
 2016-12-20  Konstantin Tokarev  <annulen@yandex.ru>
 
+        Modernize for loops in JSC
+        https://bugs.webkit.org/show_bug.cgi?id=166060
+
+        Reviewed by Yusuke Suzuki.
+
+        * API/JSCallbackObject.h:
+        (JSC::JSCallbackObjectData::JSPrivatePropertyMap::visitChildren):
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::dumpBytecode):
+        (JSC::CodeBlock::propagateTransitions):
+        (JSC::CodeBlock::stronglyVisitStrongReferences):
+        (JSC::CodeBlock::stronglyVisitWeakReferences):
+        (JSC::CodeBlock::jettison):
+        (JSC::CodeBlock::getArrayProfile):
+        (JSC::CodeBlock::tallyFrequentExitSites):
+        (JSC::CodeBlock::nameForRegister):
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::generate):
+        (JSC::BytecodeGenerator::BytecodeGenerator):
+        * bytecompiler/NodesCodegen.cpp:
+        (JSC::ObjectPatternNode::bindValue):
+        * debugger/Debugger.cpp:
+        (JSC::Debugger::applyBreakpoints):
+        * dfg/DFGCPSRethreadingPhase.cpp:
+        (JSC::DFG::CPSRethreadingPhase::canonicalizeLocalsInBlock):
+        * dfg/DFGClobberSet.cpp:
+        (JSC::DFG::ClobberSet::setOf):
+        * dfg/DFGDesiredIdentifiers.cpp:
+        (JSC::DFG::DesiredIdentifiers::reallyAdd):
+        * dfg/DFGGraph.cpp:
+        (JSC::DFG::Graph::visitChildren):
+        * dfg/DFGIntegerCheckCombiningPhase.cpp:
+        (JSC::DFG::IntegerCheckCombiningPhase::handleBlock):
+        * dfg/DFGIntegerRangeOptimizationPhase.cpp:
+        * dfg/DFGJITCompiler.cpp:
+        (JSC::DFG::JITCompiler::link):
+        * dfg/DFGLICMPhase.cpp:
+        (JSC::DFG::LICMPhase::run):
+        * dfg/DFGMaximalFlushInsertionPhase.cpp:
+        (JSC::DFG::MaximalFlushInsertionPhase::treatRootBlock):
+        * dfg/DFGPutStackSinkingPhase.cpp:
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::compileCurrentBlock):
+        (JSC::DFG::SpeculativeJIT::linkBranches):
+        * dfg/DFGStructureRegistrationPhase.cpp:
+        (JSC::DFG::StructureRegistrationPhase::run):
+        * dfg/DFGTypeCheckHoistingPhase.cpp:
+        (JSC::DFG::TypeCheckHoistingPhase::identifyRedundantStructureChecks):
+        (JSC::DFG::TypeCheckHoistingPhase::identifyRedundantArrayChecks):
+        * dfg/DFGValidate.cpp:
+        * dfg/DFGVirtualRegisterAllocationPhase.cpp:
+        (JSC::DFG::VirtualRegisterAllocationPhase::run):
+        * heap/HeapVerifier.cpp:
+        (JSC::trimDeadObjectsFromList):
+        (JSC::HeapVerifier::trimDeadObjects):
+        * heap/LiveObjectList.cpp:
+        (JSC::LiveObjectList::findObject):
+        * heap/MarkedAllocator.cpp:
+        (JSC::MarkedAllocator::isPagedOut):
+        * inspector/ScriptCallStack.cpp:
+        (Inspector::ScriptCallStack::firstNonNativeCallFrame):
+        * jit/JIT.cpp:
+        (JSC::JIT::link):
+        * parser/VariableEnvironment.cpp:
+        (JSC::VariableEnvironment::markAllVariablesAsCaptured):
+        (JSC::VariableEnvironment::hasCapturedVariables):
+        * runtime/FunctionHasExecutedCache.cpp:
+        (JSC::FunctionHasExecutedCache::hasExecutedAtOffset):
+        (JSC::FunctionHasExecutedCache::getFunctionRanges):
+        * runtime/JSPropertyNameEnumerator.cpp:
+        (JSC::JSPropertyNameEnumerator::visitChildren):
+        * runtime/TypeProfiler.cpp:
+        (JSC::TypeProfiler::findLocation):
+        * runtime/TypeSet.cpp:
+        (JSC::TypeSet::addTypeInformation):
+        (JSC::TypeSet::dumpTypes):
+        * runtime/VM.cpp:
+        (JSC::VM::gatherConservativeRoots):
+        * runtime/WeakMapData.cpp:
+        (JSC::WeakMapData::DeadKeyCleaner::visitWeakReferences):
+        (JSC::WeakMapData::DeadKeyCleaner::finalizeUnconditionally):
+        * tools/ProfileTreeNode.h:
+        (JSC::ProfileTreeNode::dumpInternal):
+        * yarr/YarrInterpreter.cpp:
+        (JSC::Yarr::ByteCompiler::emitDisjunction):
+
+2016-12-20  Konstantin Tokarev  <annulen@yandex.ru>
+
         __cpuid() requires <intrin.h> to be included
         https://bugs.webkit.org/show_bug.cgi?id=166051
 
index 75a00ed..79a12c2 100644 (file)
@@ -1769,8 +1769,8 @@ void CodeBlock::dumpBytecode(
     if (!exitSites.isEmpty()) {
         out.print(" !! frequent exits: ");
         CommaPrinter comma;
-        for (unsigned i = 0; i < exitSites.size(); ++i)
-            out.print(comma, exitSites[i].kind(), " ", exitSites[i].jitType());
+        for (auto& exitSite : exitSites)
+            out.print(comma, exitSite.kind(), " ", exitSite.jitType());
     }
 #else // ENABLE(DFG_JIT)
     UNUSED_PARAM(location);
@@ -2677,9 +2677,9 @@ void CodeBlock::propagateTransitions(const ConcurrentJSLocker&, SlotVisitor& vis
         DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
         for (auto& weakReference : dfgCommon->weakStructureReferences)
             allAreMarkedSoFar &= weakReference->markIfCheap(visitor);
-        
-        for (unsigned i = 0; i < dfgCommon->transitions.size(); ++i) {
-            if (shouldMarkTransition(dfgCommon->transitions[i])) {
+
+        for (auto& transition : dfgCommon->transitions) {
+            if (shouldMarkTransition(transition)) {
                 // If the following three things are live, then the target of the
                 // transition is also live:
                 //
@@ -2698,8 +2698,8 @@ void CodeBlock::propagateTransitions(const ConcurrentJSLocker&, SlotVisitor& vis
                 // We also short-circuit the liveness if the structure is harmless
                 // to mark (i.e. its global object and prototype are both already
                 // live).
-                
-                visitor.append(dfgCommon->transitions[i].m_to);
+
+                visitor.append(transition.m_to);
             } else
                 allAreMarkedSoFar = false;
         }
@@ -3068,12 +3068,12 @@ void CodeBlock::stronglyVisitStrongReferences(const ConcurrentJSLocker& locker,
     if (m_rareData)
         m_rareData->m_directEvalCodeCache.visitAggregate(visitor);
     visitor.appendValues(m_constantRegisters.data(), m_constantRegisters.size());
-    for (size_t i = 0; i < m_functionExprs.size(); ++i)
-        visitor.append(m_functionExprs[i]);
-    for (size_t i = 0; i < m_functionDecls.size(); ++i)
-        visitor.append(m_functionDecls[i]);
-    for (unsigned i = 0; i < m_objectAllocationProfiles.size(); ++i)
-        m_objectAllocationProfiles[i].visitAggregate(visitor);
+    for (auto& functionExpr : m_functionExprs)
+        visitor.append(functionExpr);
+    for (auto& functionDecl : m_functionDecls)
+        visitor.append(functionDecl);
+    for (auto& objectAllocationProfile : m_objectAllocationProfiles)
+        objectAllocationProfile.visitAggregate(visitor);
 
 #if ENABLE(JIT)
     for (ByValInfo* byValInfo : m_byValInfos)
@@ -3096,18 +3096,18 @@ void CodeBlock::stronglyVisitWeakReferences(const ConcurrentJSLocker&, SlotVisit
     
     DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
 
-    for (unsigned i = 0; i < dfgCommon->transitions.size(); ++i) {
-        if (!!dfgCommon->transitions[i].m_codeOrigin)
-            visitor.append(dfgCommon->transitions[i].m_codeOrigin); // Almost certainly not necessary, since the code origin should also be a weak reference. Better to be safe, though.
-        visitor.append(dfgCommon->transitions[i].m_from);
-        visitor.append(dfgCommon->transitions[i].m_to);
+    for (auto& transition : dfgCommon->transitions) {
+        if (!!transition.m_codeOrigin)
+            visitor.append(transition.m_codeOrigin); // Almost certainly not necessary, since the code origin should also be a weak reference. Better to be safe, though.
+        visitor.append(transition.m_from);
+        visitor.append(transition.m_to);
     }
-    
-    for (unsigned i = 0; i < dfgCommon->weakReferences.size(); ++i)
-        visitor.append(dfgCommon->weakReferences[i]);
 
-    for (unsigned i = 0; i < dfgCommon->weakStructureReferences.size(); ++i)
-        visitor.append(dfgCommon->weakStructureReferences[i]);
+    for (auto& weakReference : dfgCommon->weakReferences)
+        visitor.append(weakReference);
+
+    for (auto& weakStructureReference : dfgCommon->weakStructureReferences)
+        visitor.append(weakStructureReference);
 
     dfgCommon->livenessHasBeenProved = true;
 #endif    
@@ -3376,8 +3376,7 @@ void CodeBlock::jettison(Profiler::JettisonReason reason, ReoptimizationMode mod
         if (DFG::shouldDumpDisassembly()) {
             dataLog(*this, " will be jettisoned because of the following dead references:\n");
             DFG::CommonData* dfgCommon = m_jitCode->dfgCommon();
-            for (unsigned i = 0; i < dfgCommon->transitions.size(); ++i) {
-                DFG::WeakReferenceTransition& transition = dfgCommon->transitions[i];
+            for (auto& transition : dfgCommon->transitions) {
                 JSCell* origin = transition.m_codeOrigin.get();
                 JSCell* from = transition.m_from.get();
                 JSCell* to = transition.m_to.get();
@@ -3906,9 +3905,9 @@ bool CodeBlock::shouldReoptimizeFromLoopNow()
 
 ArrayProfile* CodeBlock::getArrayProfile(const ConcurrentJSLocker&, unsigned bytecodeOffset)
 {
-    for (unsigned i = 0; i < m_arrayProfiles.size(); ++i) {
-        if (m_arrayProfiles[i].bytecodeOffset() == bytecodeOffset)
-            return &m_arrayProfiles[i];
+    for (auto& m_arrayProfile : m_arrayProfiles) {
+        if (m_arrayProfile.bytecodeOffset() == bytecodeOffset)
+            return &m_arrayProfile;
     }
     return 0;
 }
@@ -4064,10 +4063,8 @@ void CodeBlock::tallyFrequentExitSites()
     switch (jitType()) {
     case JITCode::DFGJIT: {
         DFG::JITCode* jitCode = m_jitCode->dfg();
-        for (unsigned i = 0; i < jitCode->osrExit.size(); ++i) {
-            DFG::OSRExit& exit = jitCode->osrExit[i];
+        for (auto& exit : jitCode->osrExit)
             exit.considerAddingAsFrequentExitSite(profiledBlock);
-        }
         break;
     }
 
@@ -4205,10 +4202,10 @@ bool CodeBlock::usesOpcode(OpcodeID opcodeID)
 
 String CodeBlock::nameForRegister(VirtualRegister virtualRegister)
 {
-    for (unsigned i = 0; i < m_constantRegisters.size(); i++) {
-        if (m_constantRegisters[i].get().isEmpty())
+    for (auto& constantRegister : m_constantRegisters) {
+        if (constantRegister.get().isEmpty())
             continue;
-        if (SymbolTable* symbolTable = jsDynamicCast<SymbolTable*>(m_constantRegisters[i].get())) {
+        if (SymbolTable* symbolTable = jsDynamicCast<SymbolTable*>(constantRegister.get())) {
             ConcurrentJSLocker locker(symbolTable->m_lock);
             auto end = symbolTable->end(locker);
             for (auto ptr = symbolTable->begin(locker); ptr != end; ++ptr) {
index 9971d57..6ee770b 100644 (file)
@@ -126,8 +126,7 @@ ParserError BytecodeGenerator::generate()
 
     m_staticPropertyAnalyzer.kill();
 
-    for (unsigned i = 0; i < m_tryRanges.size(); ++i) {
-        TryRange& range = m_tryRanges[i];
+    for (auto& range : m_tryRanges) {
         int start = range.start->bind();
         int end = range.end->bind();
         
@@ -201,10 +200,9 @@ BytecodeGenerator::BytecodeGenerator(VM& vm, ProgramNode* programNode, UnlinkedP
 
     const FunctionStack& functionStack = programNode->functionStack();
 
-    for (size_t i = 0; i < functionStack.size(); ++i) {
-        FunctionMetadataNode* function = functionStack[i];
+    for (auto* function : functionStack)
         m_functionsToInitialize.append(std::make_pair(function, GlobalFunctionVariable));
-    }
+
     if (Options::validateBytecode()) {
         for (auto& entry : programNode->varDeclarations())
             RELEASE_ASSERT(entry.value.isVar());
index 93f4bf6..6aa4fb3 100644 (file)
@@ -3962,8 +3962,7 @@ void ObjectPatternNode::toString(StringBuilder& builder) const
 void ObjectPatternNode::bindValue(BytecodeGenerator& generator, RegisterID* rhs) const
 {
     generator.emitRequireObjectCoercible(rhs, ASCIILiteral("Right side of assignment cannot be destructured"));
-    for (size_t i = 0; i < m_targetPatterns.size(); i++) {
-        auto& target = m_targetPatterns[i];
+    for (const auto& target : m_targetPatterns) {
         RefPtr<RegisterID> temp = generator.newTemporary();
         if (!target.propertyExpression) {
             // Should not emit get_by_id for indexed ones.
index 30bba59..fad865b 100644 (file)
@@ -295,10 +295,8 @@ void Debugger::toggleBreakpoint(CodeBlock* codeBlock, Breakpoint& breakpoint, Br
 void Debugger::applyBreakpoints(CodeBlock* codeBlock)
 {
     BreakpointIDToBreakpointMap& breakpoints = m_breakpointIDToBreakpoint;
-    for (auto it = breakpoints.begin(); it != breakpoints.end(); ++it) {
-        Breakpoint& breakpoint = *it->value;
-        toggleBreakpoint(codeBlock, breakpoint, BreakpointEnabled);
-    }
+    for (auto* breakpoint : breakpoints.values())
+        toggleBreakpoint(codeBlock, *breakpoint, BreakpointEnabled);
 }
 
 class Debugger::ToggleBreakpointFunctor {
index 67b3574..fbc9c2d 100644 (file)
@@ -291,9 +291,7 @@ private:
         // but not logicalRefCount == actualRefCount). Assumes that it can break ref
         // counts.
         
-        for (unsigned nodeIndex = 0; nodeIndex < m_block->size(); ++nodeIndex) {
-            Node* node = m_block->at(nodeIndex);
-            
+        for (auto* node : *m_block) {
             m_graph.performSubstitution(node);
             
             // The rules for threaded CPS form:
index ce3398e..68e9c05 100644 (file)
@@ -129,9 +129,9 @@ void ClobberSet::dump(PrintStream& out) const
 HashSet<AbstractHeap> ClobberSet::setOf(bool direct) const
 {
     HashSet<AbstractHeap> result;
-    for (HashMap<AbstractHeap, bool>::const_iterator iter = m_clobbers.begin(); iter != m_clobbers.end(); ++iter) {
-        if (iter->value == direct)
-            result.add(iter->key);
+    for (auto& clobber : m_clobbers) {
+        if (clobber.value == direct)
+            result.add(clobber.key);
     }
     return result;
 }
index 48d77c3..b4cec6b 100644 (file)
@@ -87,8 +87,7 @@ UniquedStringImpl* DesiredIdentifiers::at(unsigned index) const
 
 void DesiredIdentifiers::reallyAdd(VM& vm, CommonData* commonData)
 {
-    for (unsigned i = 0; i < m_addedIdentifiers.size(); ++i) {
-        auto rep = m_addedIdentifiers[i];
+    for (auto rep : m_addedIdentifiers) {
         ASSERT(rep->hasAtLeastOneRef());
         commonData->dfgIdentifiers.append(Identifier::fromUid(&vm, rep));
     }
index ec4b20a..7b798e3 100644 (file)
@@ -1419,9 +1419,7 @@ void Graph::visitChildren(SlotVisitor& visitor)
         if (!block)
             continue;
         
-        for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
-            Node* node = block->at(nodeIndex);
-            
+        for (auto* node : *block) {
             switch (node->op()) {
             case CheckStructure:
                 for (unsigned i = node->structureSet().size(); i--;)
index 189b6d7..01e1e3c 100644 (file)
@@ -192,8 +192,7 @@ private:
         // First we collect Ranges. If operations within the range have enough redundancy,
         // we hoist. And then we remove additions and checks that fall within the max range.
         
-        for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
-            Node* node = block->at(nodeIndex);
+        for (auto* node : *block) {
             RangeKeyAndAddend data = rangeKeyAndAddend(node);
             if (verbose)
                 dataLog("For ", node, ": ", data, "\n");
index 76ff2dd..5905f13 100644 (file)
@@ -1109,8 +1109,7 @@ public:
             
                 m_relationships = m_relationshipsAtHead[block];
             
-                for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
-                    Node* node = block->at(nodeIndex);
+                for (auto* node : *block) {
                     if (verbose)
                         dataLog("Analysis: at ", node, ": ", listDump(sortedRelationships()), "\n");
                     executeNode(node);
index 0ac6aff..29e9231 100644 (file)
@@ -274,8 +274,7 @@ void JITCompiler::link(LinkBuffer& linkBuffer)
             start, linkBuffer.locationOf(m_ins[i].m_slowPathGenerator->label()));
     }
     
-    for (unsigned i = 0; i < m_jsCalls.size(); ++i) {
-        JSCallRecord& record = m_jsCalls[i];
+    for (auto& record : m_jsCalls) {
         CallLinkInfo& info = *record.info;
         linkBuffer.link(record.slowCall, FunctionPtr(m_vm->getCTIStub(linkCallThunkGenerator).code().executableAddress()));
         info.setCallLocations(
index e609764..75eefa9 100644 (file)
@@ -102,9 +102,7 @@ public:
             if (!loop)
                 continue;
             LoopData& data = m_data[loop->index()];
-            for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
-                Node* node = block->at(nodeIndex);
-                
+            for (auto* node : *block) {
                 // Don't look beyond parts of the code that definitely always exit.
                 // FIXME: This shouldn't be needed.
                 // https://bugs.webkit.org/show_bug.cgi?id=128584
index 3e04b0c..65e5186 100644 (file)
@@ -108,8 +108,7 @@ public:
     {
         Operands<VariableAccessData*> initialAccessData(block->variablesAtTail.numberOfArguments(), block->variablesAtTail.numberOfLocals(), nullptr);
         Operands<Node*> initialAccessNodes(block->variablesAtTail.numberOfArguments(), block->variablesAtTail.numberOfLocals(), nullptr);
-        for (unsigned i = 0; i < block->size(); i++) {
-            Node* node = block->at(i);
+        for (auto* node : *block) {
             if (!node->accessesStack(m_graph))
                 continue;
 
index 78162c7..ac37127 100644 (file)
@@ -560,9 +560,7 @@ public:
         // Finally eliminate the sunken PutStacks by turning them into Checks. This keeps whatever
         // type check they were doing.
         for (BasicBlock* block : m_graph.blocksInNaturalOrder()) {
-            for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
-                Node* node = block->at(nodeIndex);
-                
+            for (auto* node : *block) {
                 if (!putStacksToSink.contains(node))
                     continue;
                 
index 9cbdd86..bf87574 100644 (file)
@@ -1767,10 +1767,8 @@ void SpeculativeJIT::compileCurrentBlock()
     
     // Perform the most basic verification that children have been used correctly.
     if (!ASSERT_DISABLED) {
-        for (unsigned index = 0; index < m_generationInfo.size(); ++index) {
-            GenerationInfo& info = m_generationInfo[index];
+        for (auto& info : m_generationInfo)
             RELEASE_ASSERT(!info.alive());
-        }
     }
 }
 
@@ -8892,10 +8890,8 @@ void SpeculativeJIT::addBranch(const MacroAssembler::JumpList& jump, BasicBlock*
 
 void SpeculativeJIT::linkBranches()
 {
-    for (size_t i = 0; i < m_branches.size(); ++i) {
-        BranchRecord& branch = m_branches[i];
+    for (auto& branch : m_branches)
         branch.jump.linkTo(m_jit.blockHeads()[branch.destination->index], &m_jit);
-    }
 }
 
 void SpeculativeJIT::compileStoreBarrier(Node* node)
index 0b0be44..af01641 100644 (file)
@@ -71,9 +71,7 @@ public:
             if (!block)
                 continue;
         
-            for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
-                Node* node = block->at(nodeIndex);
-            
+            for (auto* node : *block) {
                 switch (node->op()) {
                 case CheckStructure:
                     assertAreRegistered(node->structureSet());
index 5f5d84d..6e00cc6 100644 (file)
@@ -272,8 +272,7 @@ private:
                     if (!shouldConsiderForHoisting<StructureTypeCheck>(variable))
                         break;
                     Node* source = node->child1().node();
-                    for (unsigned subIndexInBlock = 0; subIndexInBlock < block->size(); ++subIndexInBlock) {
-                        Node* subNode = block->at(subIndexInBlock);
+                    for (auto* subNode : *block) {
                         switch (subNode->op()) {
                         case CheckStructure: {
                             if (subNode->child1() != source)
@@ -305,8 +304,7 @@ private:
             BasicBlock* block = m_graph.block(blockIndex);
             if (!block)
                 continue;
-            for (unsigned indexInBlock = 0; indexInBlock < block->size(); ++indexInBlock) {
-                Node* node = block->at(indexInBlock);
+            for (auto* node : *block) {
                 switch (node->op()) {
                 case CheckArray: {
                     Node* child = node->child1().node();
@@ -364,8 +362,7 @@ private:
                     if (!shouldConsiderForHoisting<ArrayTypeCheck>(variable))
                         break;
                     Node* source = node->child1().node();
-                    for (unsigned subIndexInBlock = 0; subIndexInBlock < block->size(); ++subIndexInBlock) {
-                        Node* subNode = block->at(subIndexInBlock);
+                    for (auto subNode : *block) {
                         switch (subNode->op()) {
                         case CheckStructure: {
                             if (subNode->child1() != source)
index f9c22bb..f35e483 100644 (file)
@@ -638,8 +638,7 @@ private:
 
             bool didSeeExitOK = false;
             
-            for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
-                Node* node = block->at(nodeIndex);
+            for (auto* node : *block) {
                 didSeeExitOK |= node->origin.exitOK;
                 switch (node->op()) {
                 case Phi:
index f812759..7415acd 100644 (file)
@@ -59,9 +59,7 @@ public:
                 // Force usage of highest-numbered virtual registers.
                 scoreBoard.sortFree();
             }
-            for (size_t indexInBlock = 0; indexInBlock < block->size(); ++indexInBlock) {
-                Node* node = block->at(indexInBlock);
-        
+            for (auto* node : *block) {
                 if (!node->shouldGenerate())
                     continue;
                 
index c779cf1..fada794 100644 (file)
@@ -127,8 +127,7 @@ static void trimDeadObjectsFromList(HashSet<JSObject*>& knownLiveSet, LiveObject
         return;
 
     size_t liveObjectsFound = 0;
-    for (size_t i = 0; i < list.liveObjects.size(); i++) {
-        LiveObjectData& objData = list.liveObjects[i];
+    for (auto& objData : list.liveObjects) {
         if (objData.isConfirmedDead)
             continue; // Don't "resurrect" known dead objects.
         if (!knownLiveSet.contains(objData.obj)) {
@@ -145,10 +144,8 @@ void HeapVerifier::trimDeadObjects()
     HashSet<JSObject*> knownLiveSet;
 
     LiveObjectList& after = currentCycle().after;
-    for (size_t i = 0; i < after.liveObjects.size(); i++) {
-        LiveObjectData& objData = after.liveObjects[i];
+    for (auto& objData : after.liveObjects)
         knownLiveSet.add(objData.obj);
-    }
 
     trimDeadObjectsFromList(knownLiveSet, currentCycle().before);
 
index af0367d..5eb7cb9 100644 (file)
@@ -30,8 +30,7 @@ namespace JSC {
 
 LiveObjectData* LiveObjectList::findObject(JSObject* obj)
 {
-    for (size_t i = 0; i < liveObjects.size(); i++) {
-        LiveObjectData& data = liveObjects[i];
+    for (auto& data : liveObjects) {
         if (obj == data.obj)
             return &data;
     }
index 1649ec9..0280cd7 100644 (file)
@@ -51,8 +51,7 @@ MarkedAllocator::MarkedAllocator(Heap* heap, MarkedSpace* markedSpace, size_t ce
 bool MarkedAllocator::isPagedOut(double deadline)
 {
     unsigned itersSinceLastTimeCheck = 0;
-    for (size_t index = 0; index < m_blocks.size(); ++index) {
-        MarkedBlock::Handle* block = m_blocks[index];
+    for (auto* block : m_blocks) {
         if (block)
             block->block().updateNeedsDestruction();
         ++itersSinceLastTimeCheck;
index 2f8e0f6..612c448 100644 (file)
@@ -75,8 +75,7 @@ const ScriptCallFrame* ScriptCallStack::firstNonNativeCallFrame() const
     if (!m_frames.size())
         return nullptr;
 
-    for (size_t i = 0; i < m_frames.size(); ++i) {
-        const ScriptCallFrame& frame = m_frames[i];
+    for (const auto& frame : m_frames) {
         if (!frame.isNative())
             return &frame;
     }
index c2acfb3..327afb8 100644 (file)
@@ -693,8 +693,7 @@ CompilationResult JIT::link()
         return CompilationFailed;
 
     // Translate vPC offsets into addresses in JIT generated code, for switch tables.
-    for (unsigned i = 0; i < m_switches.size(); ++i) {
-        SwitchRecord record = m_switches[i];
+    for (auto& record : m_switches) {
         unsigned bytecodeOffset = record.bytecodeOffset;
 
         if (record.type != SwitchRecord::String) {
@@ -712,10 +711,9 @@ CompilationResult JIT::link()
 
             record.jumpTable.stringJumpTable->ctiDefault = patchBuffer.locationOf(m_labels[bytecodeOffset + record.defaultOffset]);
 
-            StringJumpTable::StringOffsetTable::iterator end = record.jumpTable.stringJumpTable->offsetTable.end();            
-            for (StringJumpTable::StringOffsetTable::iterator it = record.jumpTable.stringJumpTable->offsetTable.begin(); it != end; ++it) {
-                unsigned offset = it->value.branchOffset;
-                it->value.ctiOffset = offset ? patchBuffer.locationOf(m_labels[bytecodeOffset + offset]) : record.jumpTable.stringJumpTable->ctiDefault;
+            for (auto& location : record.jumpTable.stringJumpTable->offsetTable.values()) {
+                unsigned offset = location.branchOffset;
+                location.ctiOffset = offset ? patchBuffer.locationOf(m_labels[bytecodeOffset + offset]) : record.jumpTable.stringJumpTable->ctiDefault;
             }
         }
     }
@@ -725,9 +723,9 @@ CompilationResult JIT::link()
         handler.nativeCode = patchBuffer.locationOf(m_labels[handler.target]);
     }
 
-    for (Vector<CallRecord>::iterator iter = m_calls.begin(); iter != m_calls.end(); ++iter) {
-        if (iter->to)
-            patchBuffer.link(iter->from, FunctionPtr(iter->to));
+    for (auto& record : m_calls) {
+        if (record.to)
+            patchBuffer.link(record.from, FunctionPtr(record.to));
     }
 
     for (unsigned i = m_getByIds.size(); i--;)
@@ -762,8 +760,7 @@ CompilationResult JIT::link()
         }
     }
 
-    for (unsigned i = 0; i < m_callCompilationInfo.size(); ++i) {
-        CallCompilationInfo& compilationInfo = m_callCompilationInfo[i];
+    for (auto& compilationInfo : m_callCompilationInfo) {
         CallLinkInfo& info = *compilationInfo.callLinkInfo;
         info.setCallLocations(
             CodeLocationLabel(patchBuffer.locationOfNearCall(compilationInfo.callReturnLocation)),
index 6dc2fbb..692592c 100644 (file)
@@ -50,16 +50,16 @@ void VariableEnvironment::markAllVariablesAsCaptured()
 
     m_isEverythingCaptured = true; // For fast queries.
     // We must mark every entry as captured for when we iterate through m_map and entry.isCaptured() is called.
-    for (auto iter = m_map.begin(), end = m_map.end(); iter != end; ++iter) 
-        iter->value.setIsCaptured();
+    for (auto& value : m_map.values())
+        value.setIsCaptured();
 }
 
 bool VariableEnvironment::hasCapturedVariables() const
 {
     if (m_isEverythingCaptured)
         return size() > 0;
-    for (auto entry : m_map) {
-        if (entry.value.isCaptured())
+    for (auto& value : m_map.values()) {
+        if (value.isCaptured())
             return true;
     }
     return false;
index 3d7e31b..a8aadad 100644 (file)
@@ -38,10 +38,10 @@ bool FunctionHasExecutedCache::hasExecutedAtOffset(intptr_t id, unsigned offset)
     RangeMap& map = m_rangeMap.find(id)->second;
     unsigned distance = UINT_MAX;
     bool hasExecuted = false;
-    for (auto iter = map.begin(), end = map.end(); iter != end; ++iter) {
-        const FunctionRange& range = iter->first;
+    for (auto& pair : map) {
+        const FunctionRange& range = pair.first;
         if (range.m_start <= offset && offset <= range.m_end && range.m_end - range.m_start < distance) {
-            hasExecuted = iter->second;
+            hasExecuted = pair.second;
             distance = range.m_end - range.m_start;
         }
     }
@@ -88,9 +88,9 @@ Vector<std::tuple<bool, unsigned, unsigned>> FunctionHasExecutedCache::getFuncti
         return ranges;
 
     RangeMap& map = m_rangeMap.find(id)->second;
-    for (auto iter = map.begin(), end = map.end(); iter != end; ++iter) {
-        const FunctionRange& range = iter->first;
-        bool hasExecuted = iter->second;
+    for (auto& pair : map) {
+        const FunctionRange& range = pair.first;
+        bool hasExecuted = pair.second;
         ranges.append(std::tuple<bool, unsigned, unsigned>(hasExecuted, range.m_start, range.m_end));
     }
 
index 9a39e8c..67efdf7 100644 (file)
@@ -91,8 +91,8 @@ void JSPropertyNameEnumerator::visitChildren(JSCell* cell, SlotVisitor& visitor)
     Base::visitChildren(cell, visitor);
     JSPropertyNameEnumerator* thisObject = jsCast<JSPropertyNameEnumerator*>(cell);
     auto locker = holdLock(*thisObject);
-    for (unsigned i = 0; i < thisObject->m_propertyNames.size(); ++i)
-        visitor.append(thisObject->m_propertyNames[i]);
+    for (auto& propertyName : thisObject->m_propertyNames)
+        visitor.append(propertyName);
     visitor.append(thisObject->m_prototypeChain);
 }
 
index ab97492..e315c41 100644 (file)
@@ -122,8 +122,7 @@ TypeLocation* TypeProfiler::findLocation(unsigned divot, intptr_t sourceID, Type
     Vector<TypeLocation*>& bucket = m_bucketMap.find(sourceID)->value;
     TypeLocation* bestMatch = nullptr;
     unsigned distance = UINT_MAX; // Because assignments may be nested, make sure we find the closest enclosing assignment to this character offset.
-    for (size_t i = 0, size = bucket.size(); i < size; i++) {
-        TypeLocation* location = bucket.at(i);
+    for (auto* location : bucket) {
         // We found the type location that correlates to the convergence of all return statements in a function.
         // This text offset is the offset of the opening brace in a function declaration.
         if (descriptor == TypeProfilerSearchDescriptorFunctionReturn && location->m_globalVariableID == TypeProfilerReturnStatement && location->m_divotForFunctionOffsetIfReturnStatement == divot)
index 1f638c0..31ea7df 100644 (file)
@@ -58,8 +58,7 @@ void TypeSet::addTypeInformation(RuntimeType type, PassRefPtr<StructureShape> pr
             //   prototype chain, they will be merged into one shape.
             bool found = false;
             String hash = newShape->propertyHash();
-            for (size_t i = 0; i < m_structureHistory.size(); i++) {
-                RefPtr<StructureShape>& seenShape = m_structureHistory.at(i);
+            for (auto& seenShape : m_structureHistory) {
                 if (seenShape->propertyHash() == hash) {
                     found = true;
                     break;
@@ -114,16 +113,15 @@ String TypeSet::dumpTypes() const
     if (m_seenTypes & TypeSymbol)
         seen.appendLiteral("Symbol ");
 
-    for (size_t i = 0; i < m_structureHistory.size(); i++) {
-        RefPtr<StructureShape> shape = m_structureHistory.at(i);
+    for (const auto& shape : m_structureHistory) {
         seen.append(shape->m_constructorName);
         seen.append(' ');
     }
 
     if (m_structureHistory.size()) 
         seen.appendLiteral("\nStructures:[ ");
-    for (size_t i = 0; i < m_structureHistory.size(); i++) {
-        seen.append(m_structureHistory.at(i)->stringRepresentation());
+    for (const auto& shape : m_structureHistory) {
+        seen.append(shape->stringRepresentation());
         seen.append(' ');
     }
     if (m_structureHistory.size())
index 51d2305..213fcae 100644 (file)
@@ -699,8 +699,7 @@ inline void VM::updateStackLimits()
 #if ENABLE(DFG_JIT)
 void VM::gatherConservativeRoots(ConservativeRoots& conservativeRoots)
 {
-    for (size_t i = 0; i < scratchBuffers.size(); i++) {
-        ScratchBuffer* scratchBuffer = scratchBuffers[i];
+    for (auto* scratchBuffer : scratchBuffers) {
         if (scratchBuffer->activeLength()) {
             void* bufferStart = scratchBuffer->dataBuffer();
             conservativeRoots.add(bufferStart, static_cast<void*>(static_cast<char*>(bufferStart) + scratchBuffer->activeLength()));
index eba831e..16d6500 100644 (file)
@@ -108,11 +108,11 @@ void WeakMapData::clear()
 void WeakMapData::DeadKeyCleaner::visitWeakReferences(SlotVisitor& visitor)
 {
     m_liveKeyCount = 0;
-    for (auto it = m_target->m_map.begin(), end = m_target->m_map.end(); it != end; ++it) {
-        if (!Heap::isMarked(it->key))
+    for (auto& pair : m_target->m_map) {
+        if (!Heap::isMarked(pair.key))
             continue;
         m_liveKeyCount++;
-        visitor.append(it->value);
+        visitor.append(pair.value);
     }
     RELEASE_ASSERT(m_liveKeyCount <= m_target->m_map.size());
 }
@@ -126,19 +126,19 @@ void WeakMapData::DeadKeyCleaner::finalizeUnconditionally()
             return;
         Vector<JSObject*> deadEntries;
         deadEntries.reserveCapacity(deadCount);
-        for (auto it = m_target->m_map.begin(), end = m_target->m_map.end(); it != end; ++it) {
-            if (Heap::isMarked(it->key))
+        for (auto& pair : m_target->m_map) {
+            if (Heap::isMarked(pair.key))
                 continue;
-            deadEntries.uncheckedAppend(it->key);
+            deadEntries.uncheckedAppend(pair.key);
         }
-        for (size_t i = 0; i < deadEntries.size(); i++)
-            m_target->m_map.remove(deadEntries[i]);
+        for (auto& deadEntry : deadEntries)
+            m_target->m_map.remove(deadEntry);
     } else {
         MapType newMap;
-        for (auto it = m_target->m_map.begin(), end = m_target->m_map.end(); it != end; ++it) {
-            if (!Heap::isMarked(it->key))
+        for (auto& pair : m_target->m_map) {
+            if (!Heap::isMarked(pair.key))
                 continue;
-            newMap.add(it->key, it->value);
+            newMap.add(pair.key, pair.value);
         }
         m_target->m_map.swap(newMap);
     }
index 18fea77..66f4154 100644 (file)
@@ -88,9 +88,7 @@ private:
         qsort(entries.begin(), entries.size(), sizeof(MapEntry*), compareEntries);
 
         // Iterate over the children in sample-frequency order.
-        for (size_t e = 0; e < entries.size(); ++e) {
-            MapEntry* entry = entries[e];
-
+        for (auto* entry : entries) {
             // Print the number of samples, the name of this node, and the number of samples that are stack-top
             // in this node (samples directly within this node, excluding samples in children.
             for (unsigned i = 0; i < indent; ++i)
index 0a9fd82..b16e24d 100644 (file)
@@ -1943,9 +1943,7 @@ public:
                 currentCountAlreadyChecked += countToCheck;
             }
 
-            for (unsigned i = 0; i < alternative->m_terms.size(); ++i) {
-                PatternTerm& term = alternative->m_terms[i];
-
+            for (auto& term : alternative->m_terms) {
                 switch (term.type) {
                 case PatternTerm::TypeAssertionBOL:
                     assertionBOL(currentCountAlreadyChecked - term.inputPosition);