mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Move differentiator helpers into anonymous namespaces (#59294)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/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
This commit is contained in:
1 parent
3181abc5c9
commit
c9ea8bd739
2 files changed
+29
-52
No files matched your search
@@ -27,12 +27,12 @@
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
namespace {
|
||||
|
||||
enum class ReparentMode { Flatten, Unflatten };
|
||||
|
||||
#ifdef DEBUG_LOGS_DIFFER
|
||||
static std::ostream& operator<<(
|
||||
std::ostream& out,
|
||||
const ShadowViewNodePair& pair) {
|
||||
std::ostream& operator<<(std::ostream& out, const ShadowViewNodePair& pair) {
|
||||
out << pair.shadowView.tag;
|
||||
if (!pair.isConcreteView) {
|
||||
out << '\'';
|
||||
@@ -43,7 +43,7 @@ static std::ostream& operator<<(
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::ostream& operator<<(
|
||||
std::ostream& operator<<(
|
||||
std::ostream& out,
|
||||
std::vector<ShadowViewNodePair*> vec) {
|
||||
for (int i = 0; i < vec.size(); i++) {
|
||||
@@ -54,11 +54,9 @@ static std::ostream& operator<<(
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_LOGS_DIFFER
|
||||
template <typename KeyT, typename ValueT>
|
||||
static std::ostream& operator<<(
|
||||
std::ostream& operator<<(
|
||||
std::ostream& out,
|
||||
const std::unordered_map<KeyT, ValueT>& map) {
|
||||
auto it = map.begin();
|
||||
@@ -78,8 +76,7 @@ static std::ostream& operator<<(
|
||||
* possible. This can account for adding parent LayoutMetrics that are
|
||||
* important to take into account, but tricky, in (un)flattening cases.
|
||||
*/
|
||||
static std::vector<ShadowViewNodePair*>
|
||||
sliceChildShadowNodeViewPairsFromViewNodePair(
|
||||
std::vector<ShadowViewNodePair*> sliceChildShadowNodeViewPairsFromViewNodePair(
|
||||
const ShadowViewNodePair& shadowViewNodePair,
|
||||
ViewNodePairScope& scope,
|
||||
bool allowFlattened,
|
||||
@@ -97,7 +94,7 @@ sliceChildShadowNodeViewPairsFromViewNodePair(
|
||||
* `skipUnchangedChildrenInDifferentiator`, children that are the same node in
|
||||
* both trees are left out when possible: they produce no mutations.
|
||||
*/
|
||||
static void sliceMatchedPairChildren(
|
||||
void sliceMatchedPairChildren(
|
||||
const ShadowViewNodePair& oldPair,
|
||||
const ShadowViewNodePair& newPair,
|
||||
ViewNodePairScope& scope,
|
||||
@@ -148,7 +145,7 @@ static_assert(
|
||||
std::is_move_assignable<ShadowViewNodePair>::value,
|
||||
"`ShadowViewNodePair` must be `move assignable`.");
|
||||
|
||||
static void calculateShadowViewMutations(
|
||||
void calculateShadowViewMutations(
|
||||
ViewNodePairScope& scope,
|
||||
ShadowViewMutation::List& mutations,
|
||||
Tag parentTag,
|
||||
@@ -157,8 +154,6 @@ static void calculateShadowViewMutations(
|
||||
const CullingContext& oldCullingContext = {},
|
||||
const CullingContext& newCullingContext = {});
|
||||
|
||||
namespace {
|
||||
|
||||
struct OrderedMutationInstructionContainer {
|
||||
ShadowViewMutation::List createMutations{};
|
||||
ShadowViewMutation::List deleteMutations{};
|
||||
@@ -169,28 +164,7 @@ struct OrderedMutationInstructionContainer {
|
||||
ShadowViewMutation::List destructiveDownwardMutations{};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
static void updateMatchedPairSubtrees(
|
||||
ViewNodePairScope& scope,
|
||||
OrderedMutationInstructionContainer& mutationContainer,
|
||||
std::unordered_map<Tag, ShadowViewNodePair*>& newRemainingPairs,
|
||||
std::vector<ShadowViewNodePair*>& oldChildPairs,
|
||||
Tag parentTag,
|
||||
const ShadowViewNodePair& oldPair,
|
||||
const ShadowViewNodePair& newPair,
|
||||
const CullingContext& oldCullingContext,
|
||||
const CullingContext& newCullingContext);
|
||||
|
||||
static void updateMatchedPair(
|
||||
OrderedMutationInstructionContainer& mutationContainer,
|
||||
bool oldNodeFoundInOrder,
|
||||
bool newNodeFoundInOrder,
|
||||
Tag parentTag,
|
||||
const ShadowViewNodePair& oldPair,
|
||||
const ShadowViewNodePair& newPair);
|
||||
|
||||
static void calculateShadowViewMutationsFlattener(
|
||||
void calculateShadowViewMutationsFlattener(
|
||||
ViewNodePairScope& scope,
|
||||
ReparentMode reparentMode,
|
||||
OrderedMutationInstructionContainer& mutationContainer,
|
||||
@@ -211,7 +185,7 @@ static void calculateShadowViewMutationsFlattener(
|
||||
* specifically `newRemainingPairs`, and so the caller must also own
|
||||
* the ViewNodePairScope used within.
|
||||
*/
|
||||
static void updateMatchedPairSubtrees(
|
||||
void updateMatchedPairSubtrees(
|
||||
ViewNodePairScope& scope,
|
||||
OrderedMutationInstructionContainer& mutationContainer,
|
||||
std::unordered_map<Tag, ShadowViewNodePair*>& newRemainingPairs,
|
||||
@@ -362,7 +336,7 @@ static void updateMatchedPairSubtrees(
|
||||
* or INSERTTed when they are encountered via in-order-traversal, to ensure
|
||||
* correct ordering of INSERT and REMOVE mutations.
|
||||
*/
|
||||
static void updateMatchedPair(
|
||||
void updateMatchedPair(
|
||||
OrderedMutationInstructionContainer& mutationContainer,
|
||||
bool oldNodeFoundInOrder,
|
||||
bool newNodeFoundInOrder,
|
||||
@@ -455,7 +429,7 @@ static void updateMatchedPair(
|
||||
* @param parentTagForUpdate current parent in which node is mounted,
|
||||
* used for update mutations
|
||||
*/
|
||||
static void calculateShadowViewMutationsFlattener(
|
||||
void calculateShadowViewMutationsFlattener(
|
||||
ViewNodePairScope& scope,
|
||||
ReparentMode reparentMode,
|
||||
OrderedMutationInstructionContainer& mutationContainer,
|
||||
@@ -497,10 +471,8 @@ static void calculateShadowViewMutationsFlattener(
|
||||
deletionCreationCandidatePairs;
|
||||
deletionCreationCandidatePairs.reserve(treeChildren.size());
|
||||
|
||||
for (size_t index = 0;
|
||||
index < treeChildren.size() && index < treeChildren.size();
|
||||
index++) {
|
||||
auto& treeChildPair = *treeChildren[index];
|
||||
for (auto* treeChildPairPtr : treeChildren) {
|
||||
auto& treeChildPair = *treeChildPairPtr;
|
||||
|
||||
// Try to find node in other tree
|
||||
auto unvisitedIt = unvisitedOtherNodes.find(treeChildPair.shadowView.tag);
|
||||
@@ -913,7 +885,7 @@ static void calculateShadowViewMutationsFlattener(
|
||||
}
|
||||
}
|
||||
|
||||
static void calculateShadowViewMutations(
|
||||
void calculateShadowViewMutations(
|
||||
ViewNodePairScope& scope,
|
||||
ShadowViewMutation::List& mutations,
|
||||
Tag parentTag,
|
||||
@@ -1400,6 +1372,8 @@ static void calculateShadowViewMutations(
|
||||
std::back_inserter(mutations));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ShadowViewMutation::List calculateShadowViewMutations(
|
||||
const ShadowNode& oldRootShadowNode,
|
||||
const ShadowNode& newRootShadowNode) {
|
||||
|
||||
+12
-9
@@ -13,10 +13,12 @@
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
namespace {
|
||||
|
||||
/*
|
||||
* Sorting comparator for `reorderInPlaceIfNeeded`.
|
||||
*/
|
||||
static bool shouldFirstPairComesBeforeSecondOne(
|
||||
bool shouldFirstPairComesBeforeSecondOne(
|
||||
const ShadowViewNodePair* lhs,
|
||||
const ShadowViewNodePair* rhs) noexcept {
|
||||
return lhs->shadowNode->getOrderIndex() < rhs->shadowNode->getOrderIndex();
|
||||
@@ -25,8 +27,7 @@ static bool shouldFirstPairComesBeforeSecondOne(
|
||||
/*
|
||||
* Reorders pairs in-place based on `orderIndex` using a stable sort algorithm.
|
||||
*/
|
||||
static void reorderInPlaceIfNeeded(
|
||||
std::vector<ShadowViewNodePair*>& pairs) noexcept {
|
||||
void reorderInPlaceIfNeeded(std::vector<ShadowViewNodePair*>& pairs) noexcept {
|
||||
if (pairs.size() < 2) {
|
||||
return;
|
||||
}
|
||||
@@ -50,7 +51,7 @@ static void reorderInPlaceIfNeeded(
|
||||
/*
|
||||
* Whether the slicer leaves out `shadowNode` and its descendants.
|
||||
*/
|
||||
static bool isHiddenWhenSlicing(const ShadowNode& shadowNode) {
|
||||
bool isHiddenWhenSlicing(const ShadowNode& shadowNode) {
|
||||
// T153547836: Disabled on Android because the mounting infrastructure
|
||||
// is not fully ready yet.
|
||||
return
|
||||
@@ -73,7 +74,7 @@ struct ChildSlice {
|
||||
bool areChildrenFlattened;
|
||||
};
|
||||
|
||||
static ChildSlice sliceChild(
|
||||
ChildSlice sliceChild(
|
||||
const ShadowNode& parentShadowNode,
|
||||
const ShadowNode& childShadowNode,
|
||||
ShadowView shadowView,
|
||||
@@ -112,7 +113,7 @@ static ChildSlice sliceChild(
|
||||
* Adds `childSlice` to `scope` and its pair to `pairList`: statically
|
||||
* positioned pairs go before absolutely positioned ones.
|
||||
*/
|
||||
static void addChildSlice(
|
||||
void addChildSlice(
|
||||
std::vector<ShadowViewNodePair*>& pairList,
|
||||
size_t& startOfStaticIndex,
|
||||
ViewNodePairScope& scope,
|
||||
@@ -136,7 +137,7 @@ static void addChildSlice(
|
||||
}
|
||||
}
|
||||
|
||||
static void sliceChildShadowNodeViewPairsRecursively(
|
||||
void sliceChildShadowNodeViewPairsRecursively(
|
||||
std::vector<ShadowViewNodePair*>& pairList,
|
||||
size_t& startOfStaticIndex,
|
||||
ViewNodePairScope& scope,
|
||||
@@ -216,7 +217,7 @@ static void sliceChildShadowNodeViewPairsRecursively(
|
||||
/*
|
||||
* Sets the mount index of each pair after reordering.
|
||||
*/
|
||||
static void assignMountIndexes(std::vector<ShadowViewNodePair*>& pairList) {
|
||||
void assignMountIndexes(std::vector<ShadowViewNodePair*>& pairList) {
|
||||
size_t mountIndex = 0;
|
||||
for (auto child : pairList) {
|
||||
child->mountIndex =
|
||||
@@ -224,7 +225,7 @@ static void assignMountIndexes(std::vector<ShadowViewNodePair*>& pairList) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool sliceChangedChildShadowNodeViewPairsRecursively(
|
||||
bool sliceChangedChildShadowNodeViewPairsRecursively(
|
||||
std::vector<ShadowViewNodePair*>& oldPairList,
|
||||
size_t& oldStartOfStaticIndex,
|
||||
std::vector<ShadowViewNodePair*>& newPairList,
|
||||
@@ -338,6 +339,8 @@ static bool sliceChangedChildShadowNodeViewPairsRecursively(
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool sliceChangedChildShadowNodeViewPairs(
|
||||
const ShadowViewNodePair& oldShadowNodePair,
|
||||
const ShadowViewNodePair& newShadowNodePair,
|
||||
|
||||
Reference in new issue
Block a user