Skip to content

Commit

Permalink
Fabric: ShadowNodeCloneFunction signature was unified with ShadowNo…
Browse files Browse the repository at this point in the history
…de copy constructor

Summary:
@public
Now it accepts `const ShadowNode &` instead of `std::shared_ptr<const ShadowNode>` which is more reasonable (and more performant) becasue the function must not retain ownershipt.

Reviewed By: mdvacca

Differential Revision: D9073921

fbshipit-source-id: c24c475615e0f81b3e004e118dea7565d8e757b4
  • Loading branch information
shergin authored and facebook-github-bot committed Aug 4, 2018
1 parent 6230147 commit 1d93d70
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ class ConcreteComponentDescriptor: public ComponentDescriptor {

ShadowNodeCloneFunction getCloneFunction() const {
if (!cloneFunction_) {
cloneFunction_ = [this](const SharedShadowNode &shadowNode, const ShadowNodeFragment &fragment) {
assert(std::dynamic_pointer_cast<const ShadowNodeT>(shadowNode));
return this->cloneShadowNode(*shadowNode, fragment);
cloneFunction_ = [this](const ShadowNode &shadowNode, const ShadowNodeFragment &fragment) {
return this->cloneShadowNode(shadowNode, fragment);
};
}

Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/fabric/core/shadownode/ShadowNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ShadowNode::ShadowNode(

UnsharedShadowNode ShadowNode::clone(const ShadowNodeFragment &fragment) const {
assert(cloneFunction_);
return cloneFunction_(shared_from_this(), fragment);
return cloneFunction_(*this, fragment);
}

#pragma mark - Getters
Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/fabric/core/shadownode/ShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using SharedShadowNodeSharedList = std::shared_ptr<const SharedShadowNodeList>;
using SharedShadowNodeUnsharedList = std::shared_ptr<SharedShadowNodeList>;

using ShadowNodeCloneFunction = std::function<UnsharedShadowNode(
const SharedShadowNode &sourceShadowNode,
const ShadowNode &sourceShadowNode,
const ShadowNodeFragment &fragment
)>;

Expand Down
4 changes: 2 additions & 2 deletions ReactCommon/fabric/core/tests/ShadowNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ TEST(ShadowNodeTest, handleCloneFunction) {
.props = std::make_shared<const TestProps>(),
.children = ShadowNode::emptySharedShadowNodeSharedList()
},
[](const SharedShadowNode &shadowNode, const ShadowNodeFragment &fragment) {
[](const ShadowNode &shadowNode, const ShadowNodeFragment &fragment) {
return std::make_shared<TestShadowNode>(
*std::static_pointer_cast<const TestShadowNode>(shadowNode),
shadowNode,
fragment
);
}
Expand Down

0 comments on commit 1d93d70

Please sign in to comment.