Pass `YGFloatOptional` by value, not reference

Summary:
@public

`YGFloatOptional` is a 32bit type now, and can be passed by value efficiently.

Reviewed By: SidharthGuglani

Differential Revision: D13439603

fbshipit-source-id: e12539ad5b3cccbd5bc27869866ca66c023b24a7
This commit is contained in:
David Aurelio 2018-12-13 07:09:30 -08:00 committed by Facebook Github Bot
parent ada4831580
commit 688b3195c3
3 changed files with 10 additions and 11 deletions

View File

@ -175,7 +175,7 @@ void YGNode::setLayoutLastOwnerDirection(YGDirection direction) {
} }
void YGNode::setLayoutComputedFlexBasis( void YGNode::setLayoutComputedFlexBasis(
const YGFloatOptional& computedFlexBasis) { const YGFloatOptional computedFlexBasis) {
layout_.computedFlexBasis = computedFlexBasis; layout_.computedFlexBasis = computedFlexBasis;
} }
@ -451,7 +451,7 @@ float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const {
YGFloatOptional YGNode::getLeadingPadding( YGFloatOptional YGNode::getLeadingPadding(
const YGFlexDirection axis, const YGFlexDirection axis,
const float widthSize) const { const float widthSize) const {
const YGFloatOptional& paddingEdgeStart = const YGFloatOptional paddingEdgeStart =
YGResolveValue(style_.padding[YGEdgeStart], widthSize); YGResolveValue(style_.padding[YGEdgeStart], widthSize);
if (YGFlexDirectionIsRow(axis) && if (YGFlexDirectionIsRow(axis) &&
style_.padding[YGEdgeStart].unit != YGUnitUndefined && style_.padding[YGEdgeStart].unit != YGUnitUndefined &&
@ -468,11 +468,10 @@ YGFloatOptional YGNode::getLeadingPadding(
YGFloatOptional YGNode::getTrailingPadding( YGFloatOptional YGNode::getTrailingPadding(
const YGFlexDirection axis, const YGFlexDirection axis,
const float widthSize) const { const float widthSize) const {
if (YGFlexDirectionIsRow(axis) && const YGFloatOptional paddingEdgeEnd =
style_.padding[YGEdgeEnd].unit != YGUnitUndefined && YGResolveValue(style_.padding[YGEdgeEnd], widthSize);
!YGResolveValue(style_.padding[YGEdgeEnd], widthSize).isUndefined() && if (YGFlexDirectionIsRow(axis) && paddingEdgeEnd >= YGFloatOptional{0.0f}) {
YGResolveValue(style_.padding[YGEdgeEnd], widthSize).unwrap() >= 0.0f) { return paddingEdgeEnd;
return YGResolveValue(style_.padding[YGEdgeEnd], widthSize);
} }
YGFloatOptional resolvedValue = YGResolveValue( YGFloatOptional resolvedValue = YGResolveValue(

View File

@ -235,7 +235,7 @@ struct YGNode {
void setDirty(bool isDirty); void setDirty(bool isDirty);
void setLayoutLastOwnerDirection(YGDirection direction); void setLayoutLastOwnerDirection(YGDirection direction);
void setLayoutComputedFlexBasis(const YGFloatOptional& computedFlexBasis); void setLayoutComputedFlexBasis(const YGFloatOptional computedFlexBasis);
void setLayoutComputedFlexBasisGeneration( void setLayoutComputedFlexBasisGeneration(
uint32_t computedFlexBasisGeneration); uint32_t computedFlexBasisGeneration);
void setLayoutMeasuredDimension(float measuredDimension, int index); void setLayoutMeasuredDimension(float measuredDimension, int index);

View File

@ -1325,14 +1325,14 @@ static void YGNodeComputeFlexBasisForChild(
child->getConfig(), YGExperimentalFeatureWebFlexBasis) && child->getConfig(), YGExperimentalFeatureWebFlexBasis) &&
child->getLayout().computedFlexBasisGeneration != child->getLayout().computedFlexBasisGeneration !=
gCurrentGenerationCount)) { gCurrentGenerationCount)) {
const YGFloatOptional& paddingAndBorder = YGFloatOptional( const YGFloatOptional paddingAndBorder = YGFloatOptional(
YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth)); YGNodePaddingAndBorderForAxis(child, mainAxis, ownerWidth));
child->setLayoutComputedFlexBasis( child->setLayoutComputedFlexBasis(
YGFloatOptionalMax(resolvedFlexBasis, paddingAndBorder)); YGFloatOptionalMax(resolvedFlexBasis, paddingAndBorder));
} }
} else if (isMainAxisRow && isRowStyleDimDefined) { } else if (isMainAxisRow && isRowStyleDimDefined) {
// The width is definite, so use that as the flex basis. // The width is definite, so use that as the flex basis.
const YGFloatOptional& paddingAndBorder = YGFloatOptional( const YGFloatOptional paddingAndBorder = YGFloatOptional(
YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth)); YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth));
child->setLayoutComputedFlexBasis(YGFloatOptionalMax( child->setLayoutComputedFlexBasis(YGFloatOptionalMax(
@ -1341,7 +1341,7 @@ static void YGNodeComputeFlexBasisForChild(
paddingAndBorder)); paddingAndBorder));
} else if (!isMainAxisRow && isColumnStyleDimDefined) { } else if (!isMainAxisRow && isColumnStyleDimDefined) {
// The height is definite, so use that as the flex basis. // The height is definite, so use that as the flex basis.
const YGFloatOptional& paddingAndBorder = const YGFloatOptional paddingAndBorder =
YGFloatOptional(YGNodePaddingAndBorderForAxis( YGFloatOptional(YGNodePaddingAndBorderForAxis(
child, YGFlexDirectionColumn, ownerWidth)); child, YGFlexDirectionColumn, ownerWidth));
child->setLayoutComputedFlexBasis(YGFloatOptionalMax( child->setLayoutComputedFlexBasis(YGFloatOptionalMax(