diff --git a/ReactCommon/react/renderer/.clang-tidy b/ReactCommon/react/renderer/.clang-tidy index fa7256528bc..6a53acd81ed 100644 --- a/ReactCommon/react/renderer/.clang-tidy +++ b/ReactCommon/react/renderer/.clang-tidy @@ -6,5 +6,6 @@ modernize-avoid-bind, modernize-avoid-c-arrays, modernize-deprecated-headers, modernize-deprecated-ios-base-aliases, +modernize-loop-convert, ' ... diff --git a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp index cba4b798dbf..39ef31a50f7 100644 --- a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp +++ b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp @@ -1322,11 +1322,7 @@ void LayoutAnimationKeyFrameManager:: continue; } - for (auto it = inflightAnimation.keyFrames.begin(); - it != inflightAnimation.keyFrames.end(); - it++) { - auto &animatedKeyFrame = *it; - + for (auto &animatedKeyFrame : inflightAnimation.keyFrames) { if (animatedKeyFrame.invalidated) { continue; } @@ -1430,11 +1426,7 @@ void LayoutAnimationKeyFrameManager::adjustDelayedMutationIndicesForMutation( continue; } - for (auto it = inflightAnimation.keyFrames.begin(); - it != inflightAnimation.keyFrames.end(); - it++) { - auto &animatedKeyFrame = *it; - + for (auto &animatedKeyFrame : inflightAnimation.keyFrames) { if (animatedKeyFrame.invalidated) { continue; } diff --git a/ReactCommon/react/renderer/mounting/Differentiator.cpp b/ReactCommon/react/renderer/mounting/Differentiator.cpp index df09a41b1c1..f35057541ea 100644 --- a/ReactCommon/react/renderer/mounting/Differentiator.cpp +++ b/ReactCommon/react/renderer/mounting/Differentiator.cpp @@ -895,8 +895,8 @@ static void calculateShadowViewMutationsFlattener( // Construct unvisited nodes map auto unvisitedRecursiveChildPairs = TinyMap{}; - for (size_t i = 0; i < flattenedNodes.size(); i++) { - auto &newChild = *flattenedNodes[i]; + for (auto &flattenedNode : flattenedNodes) { + auto &newChild = *flattenedNode; auto unvisitedOtherNodesIt = unvisitedOtherNodes.find(newChild.shadowView.tag); @@ -959,14 +959,12 @@ static void calculateShadowViewMutationsFlattener( // If old nodes were not visited, we know that we can delete them // now. They will be removed from the hierarchy by the outermost // loop of this function. - for (auto unvisitedOldChildPairIt = - unvisitedRecursiveChildPairs.begin(); - unvisitedOldChildPairIt != unvisitedRecursiveChildPairs.end(); - unvisitedOldChildPairIt++) { - if (unvisitedOldChildPairIt->first == 0) { + for (auto &unvisitedRecursiveChildPair : + unvisitedRecursiveChildPairs) { + if (unvisitedRecursiveChildPair.first == 0) { continue; } - auto &oldFlattenedNode = *unvisitedOldChildPairIt->second; + auto &oldFlattenedNode = *unvisitedRecursiveChildPair.second; // Node unvisited - mark the entire subtree for deletion if (oldFlattenedNode.isConcreteView && @@ -1026,13 +1024,11 @@ static void calculateShadowViewMutationsFlattener( // Final step: go through creation/deletion candidates and delete/create // subtrees if they were never visited during the execution of the above // loop and recursions. - for (auto it = deletionCreationCandidatePairs.begin(); - it != deletionCreationCandidatePairs.end(); - it++) { - if (it->first == 0) { + for (auto &deletionCreationCandidatePair : deletionCreationCandidatePairs) { + if (deletionCreationCandidatePair.first == 0) { continue; } - auto &treeChildPair = *it->second; + auto &treeChildPair = *deletionCreationCandidatePair.second; // If node was visited during a flattening/unflattening recursion, // and the node in the other tree is concrete, that means it was @@ -1477,14 +1473,12 @@ static void calculateShadowViewMutationsV2( // subtrees/nodes. We do this here because we need to traverse the entire // list to make sure that a node was not reparented into an unflattened // node that occurs *after* it in the hierarchy, due to zIndex ordering. - for (auto it = deletionCandidatePairs.begin(); - it != deletionCandidatePairs.end(); - it++) { - if (it->first == 0) { + for (auto &deletionCandidatePair : deletionCandidatePairs) { + if (deletionCandidatePair.first == 0) { continue; } - auto const &oldChildPair = *it->second; + auto const &oldChildPair = *deletionCandidatePair.second; DEBUG_LOGS({ LOG(ERROR) @@ -1520,17 +1514,16 @@ static void calculateShadowViewMutationsV2( // Final step: generate Create instructions for entirely new // subtrees/nodes that are not the result of flattening or unflattening. - for (auto it = newInsertedPairs.begin(); it != newInsertedPairs.end(); - it++) { + for (auto &newInsertedPair : newInsertedPairs) { // Erased elements of a TinyMap will have a Tag/key of 0 - skip those // These *should* be removed by the map; there are currently no KNOWN // cases where TinyMap will do the wrong thing, but there are not yet // any unit tests explicitly for TinyMap, so this is safer for now. - if (it->first == 0) { + if (newInsertedPair.first == 0) { continue; } - auto const &newChildPair = *it->second; + auto const &newChildPair = *newInsertedPair.second; DEBUG_LOGS({ LOG(ERROR) diff --git a/ReactCommon/react/renderer/mounting/tests/MountingTest.cpp b/ReactCommon/react/renderer/mounting/tests/MountingTest.cpp index 8ad2395bef7..c9964e17820 100644 --- a/ReactCommon/react/renderer/mounting/tests/MountingTest.cpp +++ b/ReactCommon/react/renderer/mounting/tests/MountingTest.cpp @@ -358,9 +358,9 @@ TEST(MountingTest, testReorderingInstructionGeneration) { // The actual nodes that should be created in this transaction have a tag > // 105. EXPECT_TRUE(mutations6.size() == 25); - for (int i = 0; i < mutations6.size(); i++) { - if (mutations6[i].type == ShadowViewMutation::Create) { - EXPECT_TRUE(mutations6[i].newChildShadowView.tag > 105); + for (auto &i : mutations6) { + if (i.type == ShadowViewMutation::Create) { + EXPECT_TRUE(i.newChildShadowView.tag > 105); } } } diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp b/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp index 439fdb369af..1ab99440add 100644 --- a/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp +++ b/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp @@ -225,9 +225,10 @@ TextMeasurement TextLayoutManager::doMeasure( if (attachmentsCount > 0) { folly::dynamic fragments = serializedAttributedString["fragments"]; int attachmentIndex = 0; - for (int i = 0; i < fragments.size(); i++) { - folly::dynamic fragment = fragments[i]; - if (fragment["isAttachment"] == true) { + for (auto const &fragment : fragments) { + auto isAttachment = fragment.find("isAttachment"); + if (isAttachment != fragment.items().end() && + isAttachment->second.getBool()) { float top = attachmentData[attachmentIndex * 2]; float left = attachmentData[attachmentIndex * 2 + 1]; float width = (float)fragment["width"].getDouble();