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 e9e2ae28e0
commit 0b1780a081
2 changed files with 5 additions and 9 deletions

View File

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

View File

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