Fabric: `ShadowNode::getChildren()` now returns `vector`, not `shared_ptr`

Summary: TBD

Reviewed By: mdvacca

Differential Revision: D8988385

fbshipit-source-id: 1d1c7e0b87b32b242c69bbce44cf70fb0899cf93
This commit is contained in:
Valentin Shergin 2018-08-04 09:30:24 -07:00 committed by Facebook Github Bot
parent ca6d263d6d
commit d74346b616
9 changed files with 39 additions and 39 deletions

View File

@ -18,11 +18,11 @@ namespace react {
AttributedString BaseTextShadowNode::getAttributedString(
const TextAttributes &textAttributes,
const SharedShadowNodeSharedList &childNodes
const SharedShadowNodeList &childNodes
) const {
AttributedString attributedString;
for (const auto &childNode : *childNodes) {
for (const auto &childNode : childNodes) {
// RawShadowNode
auto rawTextShadowNode = std::dynamic_pointer_cast<const RawTextShadowNode>(childNode);
if (rawTextShadowNode) {

View File

@ -25,7 +25,7 @@ public:
*/
AttributedString getAttributedString(
const TextAttributes &baseTextAttributes,
const SharedShadowNodeSharedList &childNodes
const SharedShadowNodeList &childNodes
) const;
};

View File

@ -72,7 +72,7 @@ public:
template<typename SpecificShadowNodeT>
std::vector<SpecificShadowNodeT *> getChildrenSlice() const {
std::vector<SpecificShadowNodeT *> children;
for (const auto &childShadowNode : *getChildren()) {
for (const auto &childShadowNode : getChildren()) {
auto specificChildShadowNode = dynamic_cast<const SpecificShadowNodeT *>(childShadowNode.get());
if (specificChildShadowNode) {
children.push_back(const_cast<SpecificShadowNodeT *>(specificChildShadowNode));

View File

@ -54,8 +54,8 @@ UnsharedShadowNode ShadowNode::clone(const ShadowNodeFragment &fragment) const {
#pragma mark - Getters
SharedShadowNodeSharedList ShadowNode::getChildren() const {
return children_;
const SharedShadowNodeList &ShadowNode::getChildren() const {
return *children_;
}
SharedProps ShadowNode::getProps() const {

View File

@ -80,7 +80,7 @@ public:
virtual ComponentHandle getComponentHandle() const = 0;
virtual ComponentName getComponentName() const = 0;
SharedShadowNodeSharedList getChildren() const;
const SharedShadowNodeList &getChildren() const;
SharedProps getProps() const;
SharedEventEmitter getEventEmitter() const;
Tag getTag() const;

View File

@ -59,8 +59,8 @@ TEST(ComponentDescriptorTest, appendChild) {
descriptor->appendChild(node1, node2);
descriptor->appendChild(node1, node3);
SharedShadowNodeSharedList node1Children = node1->getChildren();
ASSERT_EQ(node1Children->size(), 2);
ASSERT_EQ(node1Children->at(0), node2);
ASSERT_EQ(node1Children->at(1), node3);
auto node1Children = node1->getChildren();
ASSERT_EQ(node1Children.size(), 2);
ASSERT_EQ(node1Children.at(0), node2);
ASSERT_EQ(node1Children.at(1), node3);
}

View File

@ -43,7 +43,7 @@ TEST(ShadowNodeTest, handleShadowNodeCreation) {
ASSERT_EQ(node->getTag(), 9);
ASSERT_EQ(node->getRootTag(), 1);
ASSERT_EQ(node->getEventEmitter(), nullptr);
ASSERT_EQ(node->getChildren()->size(), 0);
ASSERT_EQ(node->getChildren().size(), 0);
ASSERT_STREQ(node->getProps()->nativeId.c_str(), "testNativeID");
@ -78,17 +78,17 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) {
node1->appendChild(node2);
node1->appendChild(node3);
SharedShadowNodeSharedList node1Children = node1->getChildren();
ASSERT_EQ(node1Children->size(), 2);
ASSERT_EQ(node1Children->at(0), node2);
ASSERT_EQ(node1Children->at(1), node3);
auto node1Children = node1->getChildren();
ASSERT_EQ(node1Children.size(), 2);
ASSERT_EQ(node1Children.at(0), node2);
ASSERT_EQ(node1Children.at(1), node3);
auto node4 = std::make_shared<TestShadowNode>(node2, ShadowNodeFragment {});
node1->replaceChild(node2, node4);
node1Children = node1->getChildren();
ASSERT_EQ(node1Children->size(), 2);
ASSERT_EQ(node1Children->at(0), node4);
ASSERT_EQ(node1Children->at(1), node3);
ASSERT_EQ(node1Children.size(), 2);
ASSERT_EQ(node1Children.at(0), node4);
ASSERT_EQ(node1Children.at(1), node3);
// Seal the entire tree.
node1->sealRecursive();

View File

@ -11,8 +11,8 @@ namespace react {
static void calculateMutationInstructions(
TreeMutationInstructionList &instructions,
SharedShadowNode parentNode,
SharedShadowNodeSharedList oldChildNodes,
SharedShadowNodeSharedList newChildNodes
const SharedShadowNodeList &oldChildNodes,
const SharedShadowNodeList &newChildNodes
) {
// The current version of the algorithm is otimized for simplicity,
// not for performance of optimal result.
@ -26,7 +26,7 @@ static void calculateMutationInstructions(
return;
}
if (oldChildNodes->size() == 0 && newChildNodes->size() == 0) {
if (oldChildNodes.size() == 0 && newChildNodes.size() == 0) {
return;
}
@ -42,9 +42,9 @@ static void calculateMutationInstructions(
TreeMutationInstructionList destructionDownwardInstructions = {};
// Stage 1: Collectings Updates
for (index = 0; index < oldChildNodes->size() && index < newChildNodes->size(); index++) {
const auto &oldChildNode = oldChildNodes->at(index);
const auto &newChildNode = newChildNodes->at(index);
for (index = 0; index < oldChildNodes.size() && index < newChildNodes.size(); index++) {
const auto &oldChildNode = oldChildNodes.at(index);
const auto &newChildNode = newChildNodes.at(index);
if (oldChildNode->getTag() != newChildNode->getTag()) {
// Totally different nodes, updating is impossible.
@ -63,7 +63,7 @@ static void calculateMutationInstructions(
}
calculateMutationInstructions(
*(newChildNode->getChildren()->size() ? &downwardInstructions : &destructionDownwardInstructions),
*(newChildNode->getChildren().size() ? &downwardInstructions : &destructionDownwardInstructions),
oldChildNode,
oldChildNode->getChildren(),
newChildNode->getChildren()
@ -73,8 +73,8 @@ static void calculateMutationInstructions(
int lastIndexAfterFirstStage = index;
// Stage 2: Collectings Insertions
for (; index < newChildNodes->size(); index++) {
const auto &newChildNode = newChildNodes->at(index);
for (; index < newChildNodes.size(); index++) {
const auto &newChildNode = newChildNodes.at(index);
insertInstructions.push_back(
TreeMutationInstruction::Insert(
@ -88,8 +88,8 @@ static void calculateMutationInstructions(
}
// Stage 3: Collectings Deletions and Removals
for (index = lastIndexAfterFirstStage; index < oldChildNodes->size(); index++) {
const auto &oldChildNode = oldChildNodes->at(index);
for (index = lastIndexAfterFirstStage; index < oldChildNodes.size(); index++) {
const auto &oldChildNode = oldChildNodes.at(index);
// Even if the old node was (re)inserted, we have to generate `remove`
// instruction.
@ -119,7 +119,7 @@ static void calculateMutationInstructions(
destructionDownwardInstructions,
oldChildNode,
oldChildNode->getChildren(),
ShadowNode::emptySharedShadowNodeSharedList()
{}
);
} else {
// The old node *was* (re)inserted.
@ -128,7 +128,7 @@ static void calculateMutationInstructions(
const auto &newChildNode = it->second;
if (newChildNode != oldChildNode) {
calculateMutationInstructions(
*(newChildNode->getChildren()->size() ? &downwardInstructions : &destructionDownwardInstructions),
*(newChildNode->getChildren().size() ? &downwardInstructions : &destructionDownwardInstructions),
newChildNode,
oldChildNode->getChildren(),
newChildNode->getChildren()
@ -144,8 +144,8 @@ static void calculateMutationInstructions(
}
// Stage 4: Collectings Creations
for (index = lastIndexAfterFirstStage; index < newChildNodes->size(); index++) {
const auto &newChildNode = newChildNodes->at(index);
for (index = lastIndexAfterFirstStage; index < newChildNodes.size(); index++) {
const auto &newChildNode = newChildNodes.at(index);
if (insertedNodes.find(newChildNode->getTag()) == insertedNodes.end()) {
// The new node was (re)inserted, so there is no need to create it.
@ -161,7 +161,7 @@ static void calculateMutationInstructions(
calculateMutationInstructions(
downwardInstructions,
newChildNode,
ShadowNode::emptySharedShadowNodeSharedList(),
{},
newChildNode->getChildren()
);
}
@ -178,8 +178,8 @@ static void calculateMutationInstructions(
void calculateMutationInstructions(
TreeMutationInstructionList &instructions,
SharedShadowNode oldRootShadowNode,
SharedShadowNode newRootShadowNode
const SharedShadowNode &oldRootShadowNode,
const SharedShadowNode &newRootShadowNode
) {
// Root shadow nodes must have same tag.
assert(oldRootShadowNode->getTag() == newRootShadowNode->getTag());

View File

@ -18,8 +18,8 @@ namespace react {
*/
void calculateMutationInstructions(
TreeMutationInstructionList &instructions,
SharedShadowNode oldNode,
SharedShadowNode newNode
const SharedShadowNode &oldNode,
const SharedShadowNode &newNode
);
} // namespace react