Skip to content

Commit

Permalink
YGNodeBoundAxisWithinMinAndMax accepts YGFloatOptional
Browse files Browse the repository at this point in the history
Summary:
@public

Saves some calls to `.unwrap()`

Reviewed By: SidharthGuglani

Differential Revision: D13209153

fbshipit-source-id: 5658586e91496085f39b3522db6364aaeafcfe2f
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Dec 6, 2018
1 parent 10b316f commit 5719132
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ static inline bool YGNodeIsLayoutDimDefined(
static YGFloatOptional YGNodeBoundAxisWithinMinAndMax(
const YGNodeRef node,
const YGFlexDirection axis,
const float value,
const YGFloatOptional value,
const float axisSize) {
YGFloatOptional min;
YGFloatOptional max;
Expand All @@ -1226,15 +1226,15 @@ static YGFloatOptional YGNodeBoundAxisWithinMinAndMax(
node->getStyle().maxDimensions[YGDimensionWidth], axisSize);
}

if (max >= YGFloatOptional{0} && YGFloatOptional{value} > max) {
if (max >= YGFloatOptional{0} && value > max) {
return max;
}

if (min >= YGFloatOptional{0} && YGFloatOptional{value} < min) {
if (min >= YGFloatOptional{0} && value < min) {
return min;
}

return YGFloatOptional{value};
return value;
}

// Like YGNodeBoundAxisWithinMinAndMax but also ensures that the value doesn't
Expand All @@ -1246,7 +1246,9 @@ static inline float YGNodeBoundAxis(
const float axisSize,
const float widthSize) {
return YGFloatMax(
(YGNodeBoundAxisWithinMinAndMax(node, axis, value, axisSize)).unwrap(),
(YGNodeBoundAxisWithinMinAndMax(
node, axis, YGFloatOptional{value}, axisSize))
.unwrap(),
YGNodePaddingAndBorderForAxis(node, axis, widthSize));
}

Expand Down Expand Up @@ -2014,7 +2016,7 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
(YGNodeBoundAxisWithinMinAndMax(
child,
mainAxis,
(child->getLayout().computedFlexBasis).unwrap(),
child->getLayout().computedFlexBasis,
mainAxisownerSize))
.unwrap();

Expand Down Expand Up @@ -2089,13 +2091,12 @@ static float YGDistributeFreeSpaceSecondPass(
const bool isNodeFlexWrap = node->getStyle().flexWrap != YGWrapNoWrap;

for (auto currentRelativeChild : collectedFlexItemsValues.relativeChildren) {
childFlexBasis =
(YGNodeBoundAxisWithinMinAndMax(
currentRelativeChild,
mainAxis,
(currentRelativeChild->getLayout().computedFlexBasis).unwrap(),
mainAxisownerSize))
.unwrap();
childFlexBasis = (YGNodeBoundAxisWithinMinAndMax(
currentRelativeChild,
mainAxis,
currentRelativeChild->getLayout().computedFlexBasis,
mainAxisownerSize))
.unwrap();
float updatedMainSize = childFlexBasis;

if (!YGFloatIsUndefined(collectedFlexItemsValues.remainingFreeSpace) &&
Expand Down Expand Up @@ -2273,7 +2274,7 @@ static void YGDistributeFreeSpaceFirstPass(
(YGNodeBoundAxisWithinMinAndMax(
currentRelativeChild,
mainAxis,
(currentRelativeChild->getLayout().computedFlexBasis).unwrap(),
currentRelativeChild->getLayout().computedFlexBasis,
mainAxisownerSize))
.unwrap();

Expand Down Expand Up @@ -3454,7 +3455,10 @@ static void YGNodelayoutImpl(
YGFloatMin(
availableInnerMainDim + paddingAndBorderAxisMain,
(YGNodeBoundAxisWithinMinAndMax(
node, mainAxis, maxLineMainDim, mainAxisownerSize))
node,
mainAxis,
YGFloatOptional{maxLineMainDim},
mainAxisownerSize))
.unwrap()),
paddingAndBorderAxisMain),
dim[mainAxis]);
Expand Down Expand Up @@ -3484,7 +3488,8 @@ static void YGNodelayoutImpl(
(YGNodeBoundAxisWithinMinAndMax(
node,
crossAxis,
totalLineCrossDim + paddingAndBorderAxisCross,
YGFloatOptional{totalLineCrossDim +
paddingAndBorderAxisCross},
crossAxisownerSize))
.unwrap()),
paddingAndBorderAxisCross),
Expand Down

0 comments on commit 5719132

Please sign in to comment.