Skip to content

Commit c9ea8bd

Browse files
javachemeta-codesync[bot]
authored andcommitted
Move differentiator helpers into anonymous namespaces (#59294)
Summary: Pull Request resolved: #59294 Move file-local differentiator helpers and types into anonymous namespaces and remove redundant declarations and guards. No behaviour or public API changes. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D126633525 fbshipit-source-id: df1904cf170d488619417cd5607bf3fea80b273c
1 parent 3181abc commit c9ea8bd

2 files changed

Lines changed: 29 additions & 52 deletions

File tree

‎packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp‎

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
namespace facebook::react {
2929

30+
namespace {
31+
3032
enum class ReparentMode { Flatten, Unflatten };
3133

3234
#ifdef DEBUG_LOGS_DIFFER
33-
static std::ostream& operator<<(
34-
std::ostream& out,
35-
const ShadowViewNodePair& pair) {
35+
std::ostream& operator<<(std::ostream& out, const ShadowViewNodePair& pair) {
3636
out << pair.shadowView.tag;
3737
if (!pair.isConcreteView) {
3838
out << '\'';
@@ -43,7 +43,7 @@ static std::ostream& operator<<(
4343
return out;
4444
}
4545

46-
static std::ostream& operator<<(
46+
std::ostream& operator<<(
4747
std::ostream& out,
4848
std::vector<ShadowViewNodePair*> vec) {
4949
for (int i = 0; i < vec.size(); i++) {
@@ -54,11 +54,9 @@ static std::ostream& operator<<(
5454
}
5555
return out;
5656
}
57-
#endif
5857

59-
#ifdef DEBUG_LOGS_DIFFER
6058
template <typename KeyT, typename ValueT>
61-
static std::ostream& operator<<(
59+
std::ostream& operator<<(
6260
std::ostream& out,
6361
const std::unordered_map<KeyT, ValueT>& map) {
6462
auto it = map.begin();
@@ -78,8 +76,7 @@ static std::ostream& operator<<(
7876
* possible. This can account for adding parent LayoutMetrics that are
7977
* important to take into account, but tricky, in (un)flattening cases.
8078
*/
81-
static std::vector<ShadowViewNodePair*>
82-
sliceChildShadowNodeViewPairsFromViewNodePair(
79+
std::vector<ShadowViewNodePair*> sliceChildShadowNodeViewPairsFromViewNodePair(
8380
const ShadowViewNodePair& shadowViewNodePair,
8481
ViewNodePairScope& scope,
8582
bool allowFlattened,
@@ -97,7 +94,7 @@ sliceChildShadowNodeViewPairsFromViewNodePair(
9794
* `skipUnchangedChildrenInDifferentiator`, children that are the same node in
9895
* both trees are left out when possible: they produce no mutations.
9996
*/
100-
static void sliceMatchedPairChildren(
97+
void sliceMatchedPairChildren(
10198
const ShadowViewNodePair& oldPair,
10299
const ShadowViewNodePair& newPair,
103100
ViewNodePairScope& scope,
@@ -148,7 +145,7 @@ static_assert(
148145
std::is_move_assignable<ShadowViewNodePair>::value,
149146
"`ShadowViewNodePair` must be `move assignable`.");
150147

151-
static void calculateShadowViewMutations(
148+
void calculateShadowViewMutations(
152149
ViewNodePairScope& scope,
153150
ShadowViewMutation::List& mutations,
154151
Tag parentTag,
@@ -157,8 +154,6 @@ static void calculateShadowViewMutations(
157154
const CullingContext& oldCullingContext = {},
158155
const CullingContext& newCullingContext = {});
159156

160-
namespace {
161-
162157
struct OrderedMutationInstructionContainer {
163158
ShadowViewMutation::List createMutations{};
164159
ShadowViewMutation::List deleteMutations{};
@@ -169,28 +164,7 @@ struct OrderedMutationInstructionContainer {
169164
ShadowViewMutation::List destructiveDownwardMutations{};
170165
};
171166

172-
} // namespace
173-
174-
static void updateMatchedPairSubtrees(
175-
ViewNodePairScope& scope,
176-
OrderedMutationInstructionContainer& mutationContainer,
177-
std::unordered_map<Tag, ShadowViewNodePair*>& newRemainingPairs,
178-
std::vector<ShadowViewNodePair*>& oldChildPairs,
179-
Tag parentTag,
180-
const ShadowViewNodePair& oldPair,
181-
const ShadowViewNodePair& newPair,
182-
const CullingContext& oldCullingContext,
183-
const CullingContext& newCullingContext);
184-
185-
static void updateMatchedPair(
186-
OrderedMutationInstructionContainer& mutationContainer,
187-
bool oldNodeFoundInOrder,
188-
bool newNodeFoundInOrder,
189-
Tag parentTag,
190-
const ShadowViewNodePair& oldPair,
191-
const ShadowViewNodePair& newPair);
192-
193-
static void calculateShadowViewMutationsFlattener(
167+
void calculateShadowViewMutationsFlattener(
194168
ViewNodePairScope& scope,
195169
ReparentMode reparentMode,
196170
OrderedMutationInstructionContainer& mutationContainer,
@@ -211,7 +185,7 @@ static void calculateShadowViewMutationsFlattener(
211185
* specifically `newRemainingPairs`, and so the caller must also own
212186
* the ViewNodePairScope used within.
213187
*/
214-
static void updateMatchedPairSubtrees(
188+
void updateMatchedPairSubtrees(
215189
ViewNodePairScope& scope,
216190
OrderedMutationInstructionContainer& mutationContainer,
217191
std::unordered_map<Tag, ShadowViewNodePair*>& newRemainingPairs,
@@ -362,7 +336,7 @@ static void updateMatchedPairSubtrees(
362336
* or INSERTTed when they are encountered via in-order-traversal, to ensure
363337
* correct ordering of INSERT and REMOVE mutations.
364338
*/
365-
static void updateMatchedPair(
339+
void updateMatchedPair(
366340
OrderedMutationInstructionContainer& mutationContainer,
367341
bool oldNodeFoundInOrder,
368342
bool newNodeFoundInOrder,
@@ -455,7 +429,7 @@ static void updateMatchedPair(
455429
* @param parentTagForUpdate current parent in which node is mounted,
456430
* used for update mutations
457431
*/
458-
static void calculateShadowViewMutationsFlattener(
432+
void calculateShadowViewMutationsFlattener(
459433
ViewNodePairScope& scope,
460434
ReparentMode reparentMode,
461435
OrderedMutationInstructionContainer& mutationContainer,
@@ -497,10 +471,8 @@ static void calculateShadowViewMutationsFlattener(
497471
deletionCreationCandidatePairs;
498472
deletionCreationCandidatePairs.reserve(treeChildren.size());
499473

500-
for (size_t index = 0;
501-
index < treeChildren.size() && index < treeChildren.size();
502-
index++) {
503-
auto& treeChildPair = *treeChildren[index];
474+
for (auto* treeChildPairPtr : treeChildren) {
475+
auto& treeChildPair = *treeChildPairPtr;
504476

505477
// Try to find node in other tree
506478
auto unvisitedIt = unvisitedOtherNodes.find(treeChildPair.shadowView.tag);
@@ -913,7 +885,7 @@ static void calculateShadowViewMutationsFlattener(
913885
}
914886
}
915887

916-
static void calculateShadowViewMutations(
888+
void calculateShadowViewMutations(
917889
ViewNodePairScope& scope,
918890
ShadowViewMutation::List& mutations,
919891
Tag parentTag,
@@ -1400,6 +1372,8 @@ static void calculateShadowViewMutations(
14001372
std::back_inserter(mutations));
14011373
}
14021374

1375+
} // namespace
1376+
14031377
ShadowViewMutation::List calculateShadowViewMutations(
14041378
const ShadowNode& oldRootShadowNode,
14051379
const ShadowNode& newRootShadowNode) {

‎packages/react-native/ReactCommon/react/renderer/mounting/internal/sliceChildShadowNodeViewPairs.cpp‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
namespace facebook::react {
1515

16+
namespace {
17+
1618
/*
1719
* Sorting comparator for `reorderInPlaceIfNeeded`.
1820
*/
19-
static bool shouldFirstPairComesBeforeSecondOne(
21+
bool shouldFirstPairComesBeforeSecondOne(
2022
const ShadowViewNodePair* lhs,
2123
const ShadowViewNodePair* rhs) noexcept {
2224
return lhs->shadowNode->getOrderIndex() < rhs->shadowNode->getOrderIndex();
@@ -25,8 +27,7 @@ static bool shouldFirstPairComesBeforeSecondOne(
2527
/*
2628
* Reorders pairs in-place based on `orderIndex` using a stable sort algorithm.
2729
*/
28-
static void reorderInPlaceIfNeeded(
29-
std::vector<ShadowViewNodePair*>& pairs) noexcept {
30+
void reorderInPlaceIfNeeded(std::vector<ShadowViewNodePair*>& pairs) noexcept {
3031
if (pairs.size() < 2) {
3132
return;
3233
}
@@ -50,7 +51,7 @@ static void reorderInPlaceIfNeeded(
5051
/*
5152
* Whether the slicer leaves out `shadowNode` and its descendants.
5253
*/
53-
static bool isHiddenWhenSlicing(const ShadowNode& shadowNode) {
54+
bool isHiddenWhenSlicing(const ShadowNode& shadowNode) {
5455
// T153547836: Disabled on Android because the mounting infrastructure
5556
// is not fully ready yet.
5657
return
@@ -73,7 +74,7 @@ struct ChildSlice {
7374
bool areChildrenFlattened;
7475
};
7576

76-
static ChildSlice sliceChild(
77+
ChildSlice sliceChild(
7778
const ShadowNode& parentShadowNode,
7879
const ShadowNode& childShadowNode,
7980
ShadowView shadowView,
@@ -112,7 +113,7 @@ static ChildSlice sliceChild(
112113
* Adds `childSlice` to `scope` and its pair to `pairList`: statically
113114
* positioned pairs go before absolutely positioned ones.
114115
*/
115-
static void addChildSlice(
116+
void addChildSlice(
116117
std::vector<ShadowViewNodePair*>& pairList,
117118
size_t& startOfStaticIndex,
118119
ViewNodePairScope& scope,
@@ -136,7 +137,7 @@ static void addChildSlice(
136137
}
137138
}
138139

139-
static void sliceChildShadowNodeViewPairsRecursively(
140+
void sliceChildShadowNodeViewPairsRecursively(
140141
std::vector<ShadowViewNodePair*>& pairList,
141142
size_t& startOfStaticIndex,
142143
ViewNodePairScope& scope,
@@ -216,15 +217,15 @@ static void sliceChildShadowNodeViewPairsRecursively(
216217
/*
217218
* Sets the mount index of each pair after reordering.
218219
*/
219-
static void assignMountIndexes(std::vector<ShadowViewNodePair*>& pairList) {
220+
void assignMountIndexes(std::vector<ShadowViewNodePair*>& pairList) {
220221
size_t mountIndex = 0;
221222
for (auto child : pairList) {
222223
child->mountIndex =
223224
(child->isConcreteView ? mountIndex++ : static_cast<unsigned long>(-1));
224225
}
225226
}
226227

227-
static bool sliceChangedChildShadowNodeViewPairsRecursively(
228+
bool sliceChangedChildShadowNodeViewPairsRecursively(
228229
std::vector<ShadowViewNodePair*>& oldPairList,
229230
size_t& oldStartOfStaticIndex,
230231
std::vector<ShadowViewNodePair*>& newPairList,
@@ -338,6 +339,8 @@ static bool sliceChangedChildShadowNodeViewPairsRecursively(
338339
return true;
339340
}
340341

342+
} // namespace
343+
341344
bool sliceChangedChildShadowNodeViewPairs(
342345
const ShadowViewNodePair& oldShadowNodePair,
343346
const ShadowViewNodePair& newShadowNodePair,

0 commit comments

Comments
 (0)