Differ: simplify nested flattening/unflattening code
Summary: There's a case here where we do a loop, with a map loopup, and nested map lookup inside of that. It's not particularly efficient and was done because we have multiple distinct pointers to distinct ShadowViews that are backed by the same ShadowNode. Now due to previous, recent refactoring, we can simplify this case a lot. The code WAS correct before, just confusing and not particularly efficient. Tests can prove that this is still correct. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D28018996 fbshipit-source-id: a7c8148802650c88888960c9c099954e0f8bc357
This commit is contained in:
Родитель
121a84496c
Коммит
1e68a5f573
|
@ -978,36 +978,29 @@ static void calculateShadowViewMutationsFlattener(
|
|||
// If old nodes were not visited, we know that we can delete them
|
||||
// now. They will be removed from the hierarchy by the outermost
|
||||
// loop of this function.
|
||||
for (auto oldFlattenedNode : oldFlattenedNodes) {
|
||||
auto unvisitedOldChildPairIt =
|
||||
unvisitedOldChildPairs.find(oldFlattenedNode->shadowView.tag);
|
||||
if (unvisitedOldChildPairIt != unvisitedOldChildPairs.end()) {
|
||||
for (auto unvisitedOldChildPairIt = unvisitedOldChildPairs.begin();
|
||||
unvisitedOldChildPairIt != unvisitedOldChildPairs.end();
|
||||
unvisitedOldChildPairIt++) {
|
||||
if (unvisitedOldChildPairIt->first == 0) {
|
||||
continue;
|
||||
}
|
||||
auto &oldFlattenedNode = *unvisitedOldChildPairIt->second;
|
||||
|
||||
// Node unvisited - mark the entire subtree for deletion
|
||||
if (oldFlattenedNode->isConcreteView) {
|
||||
Tag tag = oldFlattenedNode->shadowView.tag;
|
||||
auto oldRemainingChildInListIt = std::find_if(
|
||||
treeChildren.begin(),
|
||||
treeChildren.end(),
|
||||
[&tag](ShadowViewNodePair *nodePair) {
|
||||
return nodePair->shadowView.tag == tag;
|
||||
});
|
||||
react_native_assert(
|
||||
oldRemainingChildInListIt != treeChildren.end());
|
||||
if (oldRemainingChildInListIt != treeChildren.end()) {
|
||||
if (oldFlattenedNode.isConcreteView &&
|
||||
!oldFlattenedNode.inOtherTree()) {
|
||||
Tag tag = oldFlattenedNode.shadowView.tag;
|
||||
auto deleteCreateIt = deletionCreationCandidatePairs.find(
|
||||
oldFlattenedNode->shadowView.tag);
|
||||
if (deleteCreateIt ==
|
||||
deletionCreationCandidatePairs.end()) {
|
||||
oldFlattenedNode.shadowView.tag);
|
||||
if (deleteCreateIt == deletionCreationCandidatePairs.end()) {
|
||||
deletionCreationCandidatePairs.insert(
|
||||
{tag, *oldRemainingChildInListIt});
|
||||
}
|
||||
}
|
||||
{tag, &oldFlattenedNode});
|
||||
}
|
||||
} else {
|
||||
// Node was visited - make sure to remove it from
|
||||
// "newRemainingPairs" map
|
||||
auto newRemainingIt =
|
||||
unvisitedOtherNodes.find(oldFlattenedNode->shadowView.tag);
|
||||
unvisitedOtherNodes.find(oldFlattenedNode.shadowView.tag);
|
||||
if (newRemainingIt != unvisitedOtherNodes.end()) {
|
||||
unvisitedOtherNodes.erase(newRemainingIt);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче