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:
parent
938e1d51c4
commit
52ed882332
|
@ -68,7 +68,7 @@ public:
|
|||
};
|
||||
|
||||
ConcreteViewShadowNode(
|
||||
const SharedShadowNode &sourceShadowNode,
|
||||
const ShadowNode &sourceShadowNode,
|
||||
const ShadowNodeFragment &fragment
|
||||
):
|
||||
BaseShadowNode(
|
||||
|
@ -76,11 +76,11 @@ public:
|
|||
fragment
|
||||
),
|
||||
AccessibleShadowNode(
|
||||
std::static_pointer_cast<const ConcreteViewShadowNode>(sourceShadowNode),
|
||||
static_cast<const ConcreteViewShadowNode &>(sourceShadowNode),
|
||||
std::static_pointer_cast<const ConcreteViewProps>(fragment.props)
|
||||
),
|
||||
YogaLayoutableShadowNode(
|
||||
*std::static_pointer_cast<const ConcreteViewShadowNode>(sourceShadowNode)
|
||||
static_cast<const ConcreteViewShadowNode &>(sourceShadowNode)
|
||||
) {
|
||||
|
||||
if (fragment.props) {
|
||||
|
|
|
@ -19,10 +19,9 @@ AccessibleShadowNode::AccessibleShadowNode(
|
|||
}
|
||||
|
||||
AccessibleShadowNode::AccessibleShadowNode(
|
||||
const SharedAccessibleShadowNode &shadowNode,
|
||||
const AccessibleShadowNode &shadowNode,
|
||||
const SharedAccessibilityProps &props
|
||||
) {
|
||||
assert(shadowNode);
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
);
|
||||
|
||||
AccessibleShadowNode(
|
||||
const SharedAccessibleShadowNode &shadowNode,
|
||||
const AccessibleShadowNode &shadowNode,
|
||||
const SharedAccessibilityProps &props = nullptr
|
||||
);
|
||||
};
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
assert(std::dynamic_pointer_cast<const ShadowNodeT>(sourceShadowNode));
|
||||
|
||||
const auto &shadowNode = std::make_shared<ShadowNodeT>(
|
||||
std::static_pointer_cast<const ShadowNodeT>(sourceShadowNode),
|
||||
*std::static_pointer_cast<const ShadowNodeT>(sourceShadowNode),
|
||||
ShadowNodeFragment {
|
||||
.props = props,
|
||||
.eventEmitter = eventEmitter,
|
||||
|
|
|
@ -40,18 +40,18 @@ ShadowNode::ShadowNode(
|
|||
}
|
||||
|
||||
ShadowNode::ShadowNode(
|
||||
const SharedShadowNode &sourceShadowNode,
|
||||
const ShadowNode &sourceShadowNode,
|
||||
const ShadowNodeFragment &fragment
|
||||
):
|
||||
tag_(fragment.tag ?: sourceShadowNode->tag_),
|
||||
rootTag_(fragment.rootTag ?: sourceShadowNode->rootTag_),
|
||||
props_(fragment.props ?: sourceShadowNode->props_),
|
||||
eventEmitter_(fragment.eventEmitter ?: sourceShadowNode->eventEmitter_),
|
||||
children_(fragment.children ?: sourceShadowNode->children_),
|
||||
localData_(fragment.localData ?: sourceShadowNode->localData_),
|
||||
cloneFunction_(sourceShadowNode->cloneFunction_),
|
||||
tag_(fragment.tag ?: sourceShadowNode.tag_),
|
||||
rootTag_(fragment.rootTag ?: sourceShadowNode.rootTag_),
|
||||
props_(fragment.props ?: sourceShadowNode.props_),
|
||||
eventEmitter_(fragment.eventEmitter ?: sourceShadowNode.eventEmitter_),
|
||||
children_(fragment.children ?: sourceShadowNode.children_),
|
||||
localData_(fragment.localData ?: sourceShadowNode.localData_),
|
||||
cloneFunction_(sourceShadowNode.cloneFunction_),
|
||||
childrenAreShared_(true),
|
||||
revision_(sourceShadowNode->revision_ + 1) {
|
||||
revision_(sourceShadowNode.revision_ + 1) {
|
||||
|
||||
assert(props_);
|
||||
assert(children_);
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
* applying fields from given `fragment`.
|
||||
*/
|
||||
ShadowNode(
|
||||
const SharedShadowNode &sourceShadowNode,
|
||||
const ShadowNode &sourceShadowNode,
|
||||
const ShadowNodeFragment &fragment
|
||||
);
|
||||
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ UnsharedRootShadowNode ShadowTree::cloneRootShadowNode(const LayoutConstraints &
|
|||
auto oldRootShadowNode = rootShadowNode_;
|
||||
const auto &props = std::make_shared<const RootProps>(*oldRootShadowNode->getProps(), layoutConstraints, layoutContext);
|
||||
auto newRootShadowNode =
|
||||
std::make_shared<RootShadowNode>(oldRootShadowNode, ShadowNodeFragment {.props = props});
|
||||
std::make_shared<RootShadowNode>(*oldRootShadowNode, ShadowNodeFragment {.props = props});
|
||||
return newRootShadowNode;
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ void ShadowTree::complete(const SharedShadowNodeUnsharedList &rootChildNodes) {
|
|||
auto oldRootShadowNode = rootShadowNode_;
|
||||
auto newRootShadowNode =
|
||||
std::make_shared<RootShadowNode>(
|
||||
oldRootShadowNode,
|
||||
*oldRootShadowNode,
|
||||
ShadowNodeFragment {
|
||||
.children = SharedShadowNodeSharedList(rootChildNodes)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue