YGNode::getChildren() should return const ref

Summary:
It's wasteful to do it by value. I'm fairly sure this is
safe, especially because
fbd332dee8 (diff-ade2a4bbd6582e2898cbd9e0fa142ab5R215)
shows that we did access by reference before.

Reviewed By: priteshrnandgaonkar, davidaurelio

Differential Revision: D8822697

fbshipit-source-id: 791bcf0fa37453f67795af727c85c8adce3b0f69
This commit is contained in:
Scott Wolchok 2018-07-13 12:34:46 -07:00 committed by Facebook Github Bot
parent e739143809
commit e589595bc9
3 changed files with 6 additions and 10 deletions

View File

@ -94,7 +94,7 @@ void YogaLayoutableShadowNode::appendChild(SharedYogaLayoutableShadowNode child)
auto yogaNodeRawPtr = &yogaNode_;
auto childYogaNodeRawPtr = &child->yogaNode_;
yogaNodeRawPtr->insertChild(childYogaNodeRawPtr, yogaNodeRawPtr->getChildrenCount());
yogaNodeRawPtr->insertChild(childYogaNodeRawPtr, yogaNodeRawPtr->getChildren().size());
if (childYogaNodeRawPtr->getOwner() == nullptr) {
child->ensureUnsealed();

View File

@ -122,14 +122,10 @@ struct YGNode {
return getOwner();
}
YGVector getChildren() const {
const YGVector& getChildren() const {
return children_;
}
uint32_t getChildrenCount() const {
return static_cast<uint32_t>(children_.size());
}
YGNodeRef getChild(uint32_t index) const {
return children_.at(index);
}

View File

@ -264,7 +264,7 @@ static YGNodeRef YGNodeDeepClone(YGNodeRef oldNode) {
YGVector vec = YGVector();
vec.reserve(oldNode->getChildren().size());
YGNodeRef childNode = nullptr;
for (auto& item : oldNode->getChildren()) {
for (auto* item : oldNode->getChildren()) {
childNode = YGNodeDeepClone(item);
childNode->setOwner(node);
vec.push_back(childNode);
@ -301,8 +301,8 @@ static void YGConfigFreeRecursive(const YGNodeRef root) {
delete root->getConfig();
}
// Delete configs recursively for childrens
for (uint32_t i = 0; i < root->getChildrenCount(); ++i) {
YGConfigFreeRecursive(root->getChild(i));
for (auto* child : root->getChildren()) {
YGConfigFreeRecursive(child);
}
}
@ -1868,7 +1868,7 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
// Add items to the current line until it's full or we run out of items.
uint32_t endOfLineIndex = startOfLineIndex;
for (; endOfLineIndex < node->getChildrenCount(); endOfLineIndex++) {
for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) {
const YGNodeRef child = node->getChild(endOfLineIndex);
if (child->getStyle().display == YGDisplayNone ||
child->getStyle().positionType == YGPositionTypeAbsolute) {