From e692ae15062b3243009602ec91d1e85fa1793cbe Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Mon, 10 Feb 2025 05:01:42 -0800 Subject: [PATCH] avoid copy of shadowView in Differentiator (#49268) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49268 changelog: [internal] ShadowView has three shared_ptr and copying those can be avoided here. Let's use std::move. Reviewed By: NickGerleman Differential Revision: D69303346 fbshipit-source-id: b13103369f6423610dd8f8ccb293e59f04acc5dc --- .../react/renderer/mounting/Differentiator.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp index 379f15eef56..6945266d502 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp @@ -340,14 +340,18 @@ static void sliceChildShadowNodeViewPairsRecursively( if (areChildrenFlattened) { storedOrigin = origin; } - scope.push_back( - {shadowView, - &childShadowNode, - areChildrenFlattened, - isConcreteView, - storedOrigin}); - if (shadowView.layoutMetrics.positionType == PositionType::Static) { + auto isPositionStatic = + shadowView.layoutMetrics.positionType == PositionType::Static; + + scope.push_back( + {.shadowView = std::move(shadowView), + .shadowNode = &childShadowNode, + .flattened = areChildrenFlattened, + .isConcreteView = isConcreteView, + .contextOrigin = storedOrigin}); + + if (isPositionStatic) { auto it = pairList.begin(); std::advance(it, startOfStaticIndex); pairList.insert(it, &scope.back());