Fabric: Using const ShadowNode & as a parameter in ShadowNode copy constructor

Summary:
@public
When we copy-construct ShadowNode, we don't need to retain a source shadow node, so there is no need to pass it as a `shared_ptr`. Passing an argument to constructor as `const &` is also more idiomatic in C++.

Reviewed By: mdvacca

Differential Revision: D8988384

fbshipit-source-id: 1279d9185fa1b4b82fd26e3040bd62fa9495b4d3
This commit is contained in:
Valentin Shergin
2018-08-04 09:30:28 -07:00
committed by Facebook Github Bot
parent 938e1d51c4
commit 52ed882332
8 changed files with 22 additions and 23 deletions

View File

@@ -62,7 +62,7 @@ TEST(ShadowNodeTest, handleShadowNodeSimpleCloning) {
},
nullptr
);
auto node2 = std::make_shared<TestShadowNode>(node, ShadowNodeFragment {});
auto node2 = std::make_shared<TestShadowNode>(*node, ShadowNodeFragment {});
ASSERT_STREQ(node->getComponentName().c_str(), "Test");
ASSERT_EQ(node->getTag(), 9);
@@ -83,7 +83,7 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) {
ASSERT_EQ(node1Children.at(0), node2);
ASSERT_EQ(node1Children.at(1), node3);
auto node4 = std::make_shared<TestShadowNode>(node2, ShadowNodeFragment {});
auto node4 = std::make_shared<TestShadowNode>(*node2, ShadowNodeFragment {});
node1->replaceChild(node2, node4);
node1Children = node1->getChildren();
ASSERT_EQ(node1Children.size(), 2);
@@ -99,7 +99,7 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) {
// No more mutation after sealing.
EXPECT_THROW(node4->setLocalData(nullptr), std::runtime_error);
auto node5 = std::make_shared<TestShadowNode>(node4, ShadowNodeFragment {});
auto node5 = std::make_shared<TestShadowNode>(*node4, ShadowNodeFragment {});
node5->setLocalData(nullptr);
ASSERT_EQ(node5->getLocalData(), nullptr);
}
@@ -119,7 +119,7 @@ TEST(ShadowNodeTest, handleCloneFunction) {
},
[](const SharedShadowNode &shadowNode, const ShadowNodeFragment &fragment) {
return std::make_shared<TestShadowNode>(
std::static_pointer_cast<const TestShadowNode>(shadowNode),
*std::static_pointer_cast<const TestShadowNode>(shadowNode),
fragment
);
}