Skip to content

Commit

Permalink
Implement findDescendantNode without cloning the tree (#39356)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39356

changelog: [internal]

`findDescendantNode` shouldn't clone the tree.

Reviewed By: javache

Differential Revision: D49095341

fbshipit-source-id: 4cd6aa6f9ba0f96d708e6a6c6b0cd55f03d8b5b1
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Sep 12, 2023
1 parent 2153184 commit 67387c3
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 67387c3

Please sign in to comment.