From 30c3ea5c3f68f62d7c675a35ed73e7cef298fb0d Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 3 May 2019 12:27:24 -0700 Subject: [PATCH] Fabric: Using move semanic in Differentiator Summary: Diffing is already pretty fast, but using move semantic should make it even faster. ShadowViews have shared pointers, so moving them can save us atomic counter bumps. Reviewed By: mdvacca Differential Revision: D15200496 fbshipit-source-id: 6fb0eb79e07cd6ae9b3100713497c634f306bc18 --- .../fabric/mounting/Differentiator.cpp | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/ReactCommon/fabric/mounting/Differentiator.cpp b/ReactCommon/fabric/mounting/Differentiator.cpp index ac051bfde13..a53c2acb0ea 100644 --- a/ReactCommon/fabric/mounting/Differentiator.cpp +++ b/ReactCommon/fabric/mounting/Differentiator.cpp @@ -46,7 +46,7 @@ static void sliceChildShadowNodeViewPairsRecursively( static ShadowViewNodePairList sliceChildShadowNodeViewPairs( const ShadowNode &shadowNode) { - ShadowViewNodePairList pairList; + auto pairList = ShadowViewNodePairList{}; sliceChildShadowNodeViewPairsRecursively(pairList, {0, 0}, shadowNode); return pairList; } @@ -195,22 +195,34 @@ static void calculateShadowViewMutations( } // All mutations in an optimal order: - mutations.insert( - mutations.end(), + std::move( destructiveDownwardMutations.begin(), - destructiveDownwardMutations.end()); - mutations.insert( - mutations.end(), updateMutations.begin(), updateMutations.end()); - mutations.insert( - mutations.end(), removeMutations.rbegin(), removeMutations.rend()); - mutations.insert( - mutations.end(), deleteMutations.begin(), deleteMutations.end()); - mutations.insert( - mutations.end(), createMutations.begin(), createMutations.end()); - mutations.insert( - mutations.end(), downwardMutations.begin(), downwardMutations.end()); - mutations.insert( - mutations.end(), insertMutations.begin(), insertMutations.end()); + destructiveDownwardMutations.end(), + std::back_inserter(mutations)); + std::move( + updateMutations.begin(), + updateMutations.end(), + std::back_inserter(mutations)); + std::move( + removeMutations.rbegin(), + removeMutations.rend(), + std::back_inserter(mutations)); + std::move( + deleteMutations.begin(), + deleteMutations.end(), + std::back_inserter(mutations)); + std::move( + createMutations.begin(), + createMutations.end(), + std::back_inserter(mutations)); + std::move( + downwardMutations.begin(), + downwardMutations.end(), + std::back_inserter(mutations)); + std::move( + insertMutations.begin(), + insertMutations.end(), + std::back_inserter(mutations)); } ShadowViewMutationList calculateShadowViewMutations( @@ -221,7 +233,8 @@ ShadowViewMutationList calculateShadowViewMutations( // Root shadow nodes must be belong the same family. assert(ShadowNode::sameFamily(oldRootShadowNode, newRootShadowNode)); - ShadowViewMutationList mutations; + auto mutations = ShadowViewMutationList{}; + mutations.reserve(256); auto oldRootShadowView = ShadowView(oldRootShadowNode); auto newRootShadowView = ShadowView(newRootShadowNode);