Updated the implementation of leading padding

Summary: Changed the arguments for the getter of leading padding to avoid copies. Added an assetion in getter of leading padding, as padding would always be defined even in the case when the user has not explicitly defined the value. In these cases it would take the default value of 0. So changing the type of `getLayoutPadding` to `YGFloatOptional`, doesn't make sense.

Reviewed By: emilsjolander

Differential Revision: D7336690

fbshipit-source-id: b2a2f010026f26fc2cc9fb35ad921da8f7017c9f
This commit is contained in:
Pritesh Nandgaonkar
2018-04-04 07:55:30 -07:00
committed by Facebook Github Bot
parent a3642541d0
commit 3e322e60e4
5 changed files with 34 additions and 14 deletions

View File

@@ -654,21 +654,21 @@ float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const {
return YGFloatMax(computedEdgeValue, 0.0f);
}
float YGNode::getLeadingPadding(
const YGFlexDirection axis,
const float widthSize) const {
YGFloatOptional YGNode::getLeadingPadding(
const YGFlexDirection& axis,
const float& widthSize) const {
const YGFloatOptional& paddingEdgeStart =
YGResolveValue(style_.padding[YGEdgeStart], widthSize);
if (YGFlexDirectionIsRow(axis) &&
style_.padding[YGEdgeStart].unit != YGUnitUndefined &&
!YGResolveValue(style_.padding[YGEdgeStart], widthSize).isUndefined() &&
YGUnwrapFloatOptional(
YGResolveValue(style_.padding[YGEdgeStart], widthSize)) > 0.0f) {
return YGUnwrapFloatOptional(YGResolveValue(style_.padding[YGEdgeStart], widthSize));
!paddingEdgeStart.isUndefined() && paddingEdgeStart.getValue() > 0.0f) {
return paddingEdgeStart;
}
float resolvedValue = YGUnwrapFloatOptional(YGResolveValue(
YGFloatOptional resolvedValue = YGResolveValue(
*YGComputedEdgeValue(style_.padding, leading[axis], &YGValueZero),
widthSize));
return YGFloatMax(resolvedValue, 0.0f);
widthSize);
return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f));
}
float YGNode::getTrailingPadding(
@@ -692,7 +692,8 @@ float YGNode::getTrailingPadding(
float YGNode::getLeadingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) const {
return getLeadingPadding(axis, widthSize) + getLeadingBorder(axis);
return YGUnwrapFloatOptional(getLeadingPadding(axis, widthSize)) +
getLeadingBorder(axis);
}
float YGNode::getTrailingPaddingAndBorder(