Skip to content

Commit

Permalink
Optimize the performance of Origami
Browse files Browse the repository at this point in the history
Reviewed By: emilsjolander

Differential Revision: D6619293

fbshipit-source-id: c1632efd97f47696b7f8bb1b3e763de92c707287
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Dec 22, 2017
1 parent 3559e42 commit a163f70
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 39 deletions.
64 changes: 30 additions & 34 deletions ReactCommon/yoga/yoga/YGNode.cpp
Expand Up @@ -34,15 +34,11 @@ YGBaselineFunc YGNode::getBaseline() const {
return baseline_; return baseline_;
} }


YGStyle YGNode::getStyle() const { YGStyle& YGNode::getStyle() {
return style_; return style_;
} }


YGLayout YGNode::getLayout() const { YGLayout& YGNode::getLayout() {
return layout_;
}

YGLayout& YGNode::getLayoutRef() {
return layout_; return layout_;
} }


Expand Down Expand Up @@ -248,21 +244,21 @@ YGNode::YGNode()
resolvedDimensions_({{YGValueUndefined, YGValueUndefined}}) {} resolvedDimensions_({{YGValueUndefined, YGValueUndefined}}) {}


YGNode::YGNode(const YGNode& node) YGNode::YGNode(const YGNode& node)
: context_(node.getContext()), : context_(node.context_),
print_(node.getPrintFunc()), print_(node.print_),
hasNewLayout_(node.getHasNewLayout()), hasNewLayout_(node.hasNewLayout_),
nodeType_(node.getNodeType()), nodeType_(node.nodeType_),
measure_(node.getMeasure()), measure_(node.measure_),
baseline_(node.getBaseline()), baseline_(node.baseline_),
style_(node.getStyle()), style_(node.style_),
layout_(node.getLayout()), layout_(node.layout_),
lineIndex_(node.getLineIndex()), lineIndex_(node.lineIndex_),
parent_(node.getParent()), parent_(node.parent_),
children_(node.getChildren()), children_(node.children_),
nextChild_(node.getNextChild()), nextChild_(node.nextChild_),
config_(node.getConfig()), config_(node.config_),
isDirty_(node.isDirty()), isDirty_(node.isDirty_),
resolvedDimensions_(node.getResolvedDimensions()) {} resolvedDimensions_(node.resolvedDimensions_) {}


YGNode::YGNode(const YGConfigRef newConfig) : YGNode() { YGNode::YGNode(const YGConfigRef newConfig) : YGNode() {
config_ = newConfig; config_ = newConfig;
Expand Down Expand Up @@ -315,8 +311,8 @@ YGNode& YGNode::operator=(const YGNode& node) {
nodeType_ = node.getNodeType(); nodeType_ = node.getNodeType();
measure_ = node.getMeasure(); measure_ = node.getMeasure();
baseline_ = node.getBaseline(); baseline_ = node.getBaseline();
style_ = node.getStyle(); style_ = node.style_;
layout_ = node.getLayout(); layout_ = node.layout_;
lineIndex_ = node.getLineIndex(); lineIndex_ = node.getLineIndex();
parent_ = node.getParent(); parent_ = node.getParent();
children_ = node.getChildren(); children_ = node.getChildren();
Expand All @@ -330,28 +326,28 @@ YGNode& YGNode::operator=(const YGNode& node) {


YGValue YGNode::marginLeadingValue(const YGFlexDirection axis) const { YGValue YGNode::marginLeadingValue(const YGFlexDirection axis) const {
if (YGFlexDirectionIsRow(axis) && if (YGFlexDirectionIsRow(axis) &&
getStyle().margin[YGEdgeStart].unit != YGUnitUndefined) { style_.margin[YGEdgeStart].unit != YGUnitUndefined) {
return getStyle().margin[YGEdgeStart]; return style_.margin[YGEdgeStart];
} else { } else {
return getStyle().margin[leading[axis]]; return style_.margin[leading[axis]];
} }
} }


YGValue YGNode::marginTrailingValue(const YGFlexDirection axis) const { YGValue YGNode::marginTrailingValue(const YGFlexDirection axis) const {
if (YGFlexDirectionIsRow(axis) && if (YGFlexDirectionIsRow(axis) &&
getStyle().margin[YGEdgeEnd].unit != YGUnitUndefined) { style_.margin[YGEdgeEnd].unit != YGUnitUndefined) {
return getStyle().margin[YGEdgeEnd]; return style_.margin[YGEdgeEnd];
} else { } else {
return getStyle().margin[trailing[axis]]; return style_.margin[trailing[axis]];
} }
} }


YGValue YGNode::resolveFlexBasisPtr() const { YGValue YGNode::resolveFlexBasisPtr() const {
YGValue flexBasis = getStyle().flexBasis; YGValue flexBasis = style_.flexBasis;
if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) { if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) {
return flexBasis; return flexBasis;
} }
if (!YGFloatIsUndefined(getStyle().flex) && getStyle().flex > 0.0f) { if (!YGFloatIsUndefined(style_.flex) && style_.flex > 0.0f) {
return config_->useWebDefaults ? YGValueAuto : YGValueZero; return config_->useWebDefaults ? YGValueAuto : YGValueZero;
} }
return YGValueAuto; return YGValueAuto;
Expand All @@ -361,10 +357,10 @@ void YGNode::resolveDimension() {
for (uint32_t dim = YGDimensionWidth; dim < YGDimensionCount; dim++) { for (uint32_t dim = YGDimensionWidth; dim < YGDimensionCount; dim++) {
if (getStyle().maxDimensions[dim].unit != YGUnitUndefined && if (getStyle().maxDimensions[dim].unit != YGUnitUndefined &&
YGValueEqual( YGValueEqual(
getStyle().maxDimensions[dim], getStyle().minDimensions[dim])) { getStyle().maxDimensions[dim], style_.minDimensions[dim])) {
resolvedDimensions_[dim] = getStyle().maxDimensions[dim]; resolvedDimensions_[dim] = style_.maxDimensions[dim];
} else { } else {
resolvedDimensions_[dim] = getStyle().dimensions[dim]; resolvedDimensions_[dim] = style_.dimensions[dim];
} }
} }
} }
Expand Down
7 changes: 4 additions & 3 deletions ReactCommon/yoga/yoga/YGNode.h
Expand Up @@ -60,9 +60,10 @@ struct YGNode {
YGNodeType getNodeType() const; YGNodeType getNodeType() const;
YGMeasureFunc getMeasure() const; YGMeasureFunc getMeasure() const;
YGBaselineFunc getBaseline() const; YGBaselineFunc getBaseline() const;
YGStyle getStyle() const; // For Perfomance reasons passing as reference.
YGLayout getLayout() const; YGStyle& getStyle();
YGLayout& getLayoutRef(); // TODO remove its use // For Perfomance reasons passing as reference.
YGLayout& getLayout();
uint32_t getLineIndex() const; uint32_t getLineIndex() const;
YGNodeRef getParent() const; YGNodeRef getParent() const;
YGVector getChildren() const; YGVector getChildren() const;
Expand Down
4 changes: 2 additions & 2 deletions ReactCommon/yoga/yoga/Yoga.cpp
Expand Up @@ -1803,7 +1803,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node,
} }


static void YGZeroOutLayoutRecursivly(const YGNodeRef node) { static void YGZeroOutLayoutRecursivly(const YGNodeRef node) {
memset(&(node->getLayoutRef()), 0, sizeof(YGLayout)); memset(&(node->getLayout()), 0, sizeof(YGLayout));
node->setHasNewLayout(true); node->setHasNewLayout(true);
YGCloneChildrenIfNeeded(node); YGCloneChildrenIfNeeded(node);
const uint32_t childCount = YGNodeGetChildCount(node); const uint32_t childCount = YGNodeGetChildCount(node);
Expand Down Expand Up @@ -3341,7 +3341,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
const bool performLayout, const bool performLayout,
const char *reason, const char *reason,
const YGConfigRef config) { const YGConfigRef config) {
YGLayout* layout = &node->getLayoutRef(); YGLayout* layout = &node->getLayout();


gDepth++; gDepth++;


Expand Down

0 comments on commit a163f70

Please sign in to comment.