Skip to content

Commit a163f70

Browse files
priteshrnandgaonkarfacebook-github-bot
authored andcommittedDec 22, 2017
Optimize the performance of Origami
Reviewed By: emilsjolander Differential Revision: D6619293 fbshipit-source-id: c1632efd97f47696b7f8bb1b3e763de92c707287
1 parent 3559e42 commit a163f70

File tree

3 files changed

+36
-39
lines changed

3 files changed

+36
-39
lines changed
 

Diff for: ‎ReactCommon/yoga/yoga/YGNode.cpp

+30-34
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@ YGBaselineFunc YGNode::getBaseline() const {
3434
return baseline_;
3535
}
3636

37-
YGStyle YGNode::getStyle() const {
37+
YGStyle& YGNode::getStyle() {
3838
return style_;
3939
}
4040

41-
YGLayout YGNode::getLayout() const {
42-
return layout_;
43-
}
44-
45-
YGLayout& YGNode::getLayoutRef() {
41+
YGLayout& YGNode::getLayout() {
4642
return layout_;
4743
}
4844

@@ -248,21 +244,21 @@ YGNode::YGNode()
248244
resolvedDimensions_({{YGValueUndefined, YGValueUndefined}}) {}
249245

250246
YGNode::YGNode(const YGNode& node)
251-
: context_(node.getContext()),
252-
print_(node.getPrintFunc()),
253-
hasNewLayout_(node.getHasNewLayout()),
254-
nodeType_(node.getNodeType()),
255-
measure_(node.getMeasure()),
256-
baseline_(node.getBaseline()),
257-
style_(node.getStyle()),
258-
layout_(node.getLayout()),
259-
lineIndex_(node.getLineIndex()),
260-
parent_(node.getParent()),
261-
children_(node.getChildren()),
262-
nextChild_(node.getNextChild()),
263-
config_(node.getConfig()),
264-
isDirty_(node.isDirty()),
265-
resolvedDimensions_(node.getResolvedDimensions()) {}
247+
: context_(node.context_),
248+
print_(node.print_),
249+
hasNewLayout_(node.hasNewLayout_),
250+
nodeType_(node.nodeType_),
251+
measure_(node.measure_),
252+
baseline_(node.baseline_),
253+
style_(node.style_),
254+
layout_(node.layout_),
255+
lineIndex_(node.lineIndex_),
256+
parent_(node.parent_),
257+
children_(node.children_),
258+
nextChild_(node.nextChild_),
259+
config_(node.config_),
260+
isDirty_(node.isDirty_),
261+
resolvedDimensions_(node.resolvedDimensions_) {}
266262

267263
YGNode::YGNode(const YGConfigRef newConfig) : YGNode() {
268264
config_ = newConfig;
@@ -315,8 +311,8 @@ YGNode& YGNode::operator=(const YGNode& node) {
315311
nodeType_ = node.getNodeType();
316312
measure_ = node.getMeasure();
317313
baseline_ = node.getBaseline();
318-
style_ = node.getStyle();
319-
layout_ = node.getLayout();
314+
style_ = node.style_;
315+
layout_ = node.layout_;
320316
lineIndex_ = node.getLineIndex();
321317
parent_ = node.getParent();
322318
children_ = node.getChildren();
@@ -330,28 +326,28 @@ YGNode& YGNode::operator=(const YGNode& node) {
330326

331327
YGValue YGNode::marginLeadingValue(const YGFlexDirection axis) const {
332328
if (YGFlexDirectionIsRow(axis) &&
333-
getStyle().margin[YGEdgeStart].unit != YGUnitUndefined) {
334-
return getStyle().margin[YGEdgeStart];
329+
style_.margin[YGEdgeStart].unit != YGUnitUndefined) {
330+
return style_.margin[YGEdgeStart];
335331
} else {
336-
return getStyle().margin[leading[axis]];
332+
return style_.margin[leading[axis]];
337333
}
338334
}
339335

340336
YGValue YGNode::marginTrailingValue(const YGFlexDirection axis) const {
341337
if (YGFlexDirectionIsRow(axis) &&
342-
getStyle().margin[YGEdgeEnd].unit != YGUnitUndefined) {
343-
return getStyle().margin[YGEdgeEnd];
338+
style_.margin[YGEdgeEnd].unit != YGUnitUndefined) {
339+
return style_.margin[YGEdgeEnd];
344340
} else {
345-
return getStyle().margin[trailing[axis]];
341+
return style_.margin[trailing[axis]];
346342
}
347343
}
348344

349345
YGValue YGNode::resolveFlexBasisPtr() const {
350-
YGValue flexBasis = getStyle().flexBasis;
346+
YGValue flexBasis = style_.flexBasis;
351347
if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) {
352348
return flexBasis;
353349
}
354-
if (!YGFloatIsUndefined(getStyle().flex) && getStyle().flex > 0.0f) {
350+
if (!YGFloatIsUndefined(style_.flex) && style_.flex > 0.0f) {
355351
return config_->useWebDefaults ? YGValueAuto : YGValueZero;
356352
}
357353
return YGValueAuto;
@@ -361,10 +357,10 @@ void YGNode::resolveDimension() {
361357
for (uint32_t dim = YGDimensionWidth; dim < YGDimensionCount; dim++) {
362358
if (getStyle().maxDimensions[dim].unit != YGUnitUndefined &&
363359
YGValueEqual(
364-
getStyle().maxDimensions[dim], getStyle().minDimensions[dim])) {
365-
resolvedDimensions_[dim] = getStyle().maxDimensions[dim];
360+
getStyle().maxDimensions[dim], style_.minDimensions[dim])) {
361+
resolvedDimensions_[dim] = style_.maxDimensions[dim];
366362
} else {
367-
resolvedDimensions_[dim] = getStyle().dimensions[dim];
363+
resolvedDimensions_[dim] = style_.dimensions[dim];
368364
}
369365
}
370366
}

Diff for: ‎ReactCommon/yoga/yoga/YGNode.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ struct YGNode {
6060
YGNodeType getNodeType() const;
6161
YGMeasureFunc getMeasure() const;
6262
YGBaselineFunc getBaseline() const;
63-
YGStyle getStyle() const;
64-
YGLayout getLayout() const;
65-
YGLayout& getLayoutRef(); // TODO remove its use
63+
// For Perfomance reasons passing as reference.
64+
YGStyle& getStyle();
65+
// For Perfomance reasons passing as reference.
66+
YGLayout& getLayout();
6667
uint32_t getLineIndex() const;
6768
YGNodeRef getParent() const;
6869
YGVector getChildren() const;

Diff for: ‎ReactCommon/yoga/yoga/Yoga.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node,
18031803
}
18041804

18051805
static void YGZeroOutLayoutRecursivly(const YGNodeRef node) {
1806-
memset(&(node->getLayoutRef()), 0, sizeof(YGLayout));
1806+
memset(&(node->getLayout()), 0, sizeof(YGLayout));
18071807
node->setHasNewLayout(true);
18081808
YGCloneChildrenIfNeeded(node);
18091809
const uint32_t childCount = YGNodeGetChildCount(node);
@@ -3341,7 +3341,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
33413341
const bool performLayout,
33423342
const char *reason,
33433343
const YGConfigRef config) {
3344-
YGLayout* layout = &node->getLayoutRef();
3344+
YGLayout* layout = &node->getLayout();
33453345

33463346
gDepth++;
33473347

0 commit comments

Comments
 (0)
Please sign in to comment.