From d19a2178b6be29c9c851186cfd85251c631bfde7 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Tue, 1 Oct 2024 17:31:46 -0700 Subject: [PATCH] remove use of type alias from Differentiator (#46762) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46762 changelog: [internal] Typealias NonOwningList obscures the underlaying type and provides limited benefit. Using std::vector is more readable. Reviewed By: NickGerleman Differential Revision: D63396285 fbshipit-source-id: 70cda3f33a7649cabbf5888fbefe0610d2c002b3 --- .../renderer/mounting/Differentiator.cpp | 31 +++++++++---------- .../react/renderer/mounting/Differentiator.h | 4 +-- .../react/renderer/mounting/stubs/stubs.cpp | 2 +- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp index a65243fac18..caa55984462 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp @@ -195,7 +195,7 @@ static bool shouldFirstPairComesBeforeSecondOne( * Reorders pairs in-place based on `orderIndex` using a stable sort algorithm. */ static void reorderInPlaceIfNeeded( - ShadowViewNodePair::NonOwningList& pairs) noexcept { + std::vector& pairs) noexcept { if (pairs.size() < 2) { return; } @@ -217,7 +217,7 @@ static void reorderInPlaceIfNeeded( } static void sliceChildShadowNodeViewPairsRecursively( - ShadowViewNodePair::NonOwningList& pairList, + std::vector& pairList, size_t& startOfStaticIndex, ViewNodePairScope& scope, Point layoutOffset, @@ -284,13 +284,13 @@ static void sliceChildShadowNodeViewPairsRecursively( } } -ShadowViewNodePair::NonOwningList sliceChildShadowNodeViewPairs( +std::vector sliceChildShadowNodeViewPairs( const ShadowViewNodePair& shadowNodePair, ViewNodePairScope& scope, bool allowFlattened, Point layoutOffset) { const auto& shadowNode = *shadowNodePair.shadowNode; - auto pairList = ShadowViewNodePair::NonOwningList{}; + auto pairList = std::vector{}; if (shadowNodePair.flattened && shadowNodePair.isConcreteView && !allowFlattened) { @@ -319,7 +319,7 @@ ShadowViewNodePair::NonOwningList sliceChildShadowNodeViewPairs( * possible. This can account for adding parent LayoutMetrics that are * important to take into account, but tricky, in (un)flattening cases. */ -static ShadowViewNodePair::NonOwningList +static std::vector sliceChildShadowNodeViewPairsFromViewNodePair( const ShadowViewNodePair& shadowViewNodePair, ViewNodePairScope& scope, @@ -345,8 +345,8 @@ static_assert( std::is_move_constructible::value, "`ShadowViewNodePair` must be `move constructible`."); static_assert( - std::is_move_constructible::value, - "`ShadowViewNodePair::NonOwningList` must be `move constructible`."); + std::is_move_constructible>::value, + "`std::vector` must be `move constructible`."); static_assert( std::is_move_assignable::value, @@ -357,16 +357,13 @@ static_assert( static_assert( std::is_move_assignable::value, "`ShadowViewNodePair` must be `move assignable`."); -static_assert( - std::is_move_assignable::value, - "`ShadowViewNodePair::NonOwningList` must be `move assignable`."); static void calculateShadowViewMutations( ViewNodePairScope& scope, ShadowViewMutation::List& mutations, const ShadowView& parentShadowView, - ShadowViewNodePair::NonOwningList&& oldChildPairs, - ShadowViewNodePair::NonOwningList&& newChildPairs); + std::vector&& oldChildPairs, + std::vector&& newChildPairs); struct OrderedMutationInstructionContainer { ShadowViewMutation::List createMutations{}; @@ -382,7 +379,7 @@ static void updateMatchedPairSubtrees( ViewNodePairScope& scope, OrderedMutationInstructionContainer& mutationContainer, TinyMap& newRemainingPairs, - ShadowViewNodePair::NonOwningList& oldChildPairs, + std::vector& oldChildPairs, const ShadowView& parentShadowView, const ShadowViewNodePair& oldPair, const ShadowViewNodePair& newPair); @@ -417,7 +414,7 @@ static void updateMatchedPairSubtrees( ViewNodePairScope& scope, OrderedMutationInstructionContainer& mutationContainer, TinyMap& newRemainingPairs, - ShadowViewNodePair::NonOwningList& oldChildPairs, + std::vector& oldChildPairs, const ShadowView& parentShadowView, const ShadowViewNodePair& oldPair, const ShadowViewNodePair& newPair) { @@ -638,7 +635,7 @@ static void calculateShadowViewMutationsFlattener( }); // Step 1: iterate through entire tree - ShadowViewNodePair::NonOwningList treeChildren = + std::vector treeChildren = sliceChildShadowNodeViewPairsFromViewNodePair(node, scope); DEBUG_LOGS({ @@ -1054,8 +1051,8 @@ static void calculateShadowViewMutations( ViewNodePairScope& scope, ShadowViewMutation::List& mutations, const ShadowView& parentShadowView, - ShadowViewNodePair::NonOwningList&& oldChildPairs, - ShadowViewNodePair::NonOwningList&& newChildPairs) { + std::vector&& oldChildPairs, + std::vector&& newChildPairs) { if (oldChildPairs.empty() && newChildPairs.empty()) { return; } diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.h b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.h index c564b0a94ba..cf8dcf8cc0d 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.h +++ b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.h @@ -19,8 +19,6 @@ namespace facebook::react { * This is not exposed to the mounting layer. */ struct ShadowViewNodePair final { - using NonOwningList = std::vector; - ShadowView shadowView; const ShadowNode* shadowNode; @@ -94,7 +92,7 @@ ShadowViewMutation::List calculateShadowViewMutations( * flattened view hierarchy. The V2 version preserves nodes even if they do * not form views and their children are flattened. */ -ShadowViewNodePair::NonOwningList sliceChildShadowNodeViewPairs( +std::vector sliceChildShadowNodeViewPairs( const ShadowViewNodePair& shadowNodePair, ViewNodePairScope& viewNodePairScope, bool allowFlattened = false, diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.cpp index 3e96aa93f89..b6de0a7ba7a 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.cpp @@ -43,7 +43,7 @@ static void calculateShadowViewMutationsForNewTree( ShadowViewMutation::List& mutations, ViewNodePairScope& scope, const ShadowView& parentShadowView, - ShadowViewNodePair::NonOwningList newChildPairs) { + std::vector newChildPairs) { // Sorting pairs based on `orderIndex` if needed. reorderInPlaceIfNeeded(newChildPairs);