Fabric: ShadowNodeCloneFunction signature was unified with ShadowNode 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
This commit is contained in:
Valentin Shergin 2018-08-04 09:30:37 -07:00 committed by Facebook Github Bot
parent 6230147e73
commit 1d93d70af4
4 changed files with 6 additions and 7 deletions

View File

@ -113,9 +113,8 @@ private:
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);
};
}

View File

@ -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

View File

@ -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
)>;

View File

@ -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
);
}