mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Implement findDescendantNode without cloning the tree (#39356)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39356 changelog: [internal] `findDescendantNode` shouldn't clone the tree. Reviewed By: javache Differential Revision: D49095341 fbshipit-source-id: 4cd6aa6f9ba0f96d708e6a6c6b0cd55f03d8b5b1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2153184c77
commit
67387c3c91
+16
-8
@@ -36,23 +36,31 @@ class DummyShadowTreeDelegate : public ShadowTreeDelegate {
|
||||
bool mountSynchronously) const override{};
|
||||
};
|
||||
|
||||
inline const ShadowNode* findDescendantNode(
|
||||
namespace {
|
||||
const ShadowNode* findDescendantNode(
|
||||
const ShadowNode& shadowNode,
|
||||
const ShadowNodeFamily& family) {
|
||||
const ShadowNode* result = nullptr;
|
||||
shadowNode.cloneTree(family, [&](const ShadowNode& oldShadowNode) {
|
||||
result = &oldShadowNode;
|
||||
return oldShadowNode.clone({});
|
||||
});
|
||||
return result;
|
||||
if (&shadowNode.getFamily() == &family) {
|
||||
return &shadowNode;
|
||||
}
|
||||
|
||||
for (auto childNode : shadowNode.getChildren()) {
|
||||
auto descendant = findDescendantNode(*childNode, family);
|
||||
if (descendant != nullptr) {
|
||||
return descendant;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline const ShadowNode* findDescendantNode(
|
||||
const ShadowNode* findDescendantNode(
|
||||
const ShadowTree& shadowTree,
|
||||
const ShadowNodeFamily& family) {
|
||||
return findDescendantNode(
|
||||
*shadowTree.getCurrentRevision().rootShadowNode, family);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(StateReconciliationTest, testStateReconciliation) {
|
||||
auto builder = simpleComponentBuilder();
|
||||
|
||||
Reference in New Issue
Block a user