From bb139d3f91147c6c62369f16311bfb9d035f31b7 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Wed, 4 Apr 2018 07:55:25 -0700 Subject: [PATCH] Remove the use of YGUnwrapOptional from YGConstrainedMaxSizeForMode Summary: Remove the use of YGUnwrapOptional from YGConstrainedMaxSizeForMode Reviewed By: emilsjolander Differential Revision: D7322743 fbshipit-source-id: d825c60bcdc9ecdc0c784a215dc6b1b8a7a7860e --- yoga/YGFloatOptional.cpp | 19 +++++++++++++++++-- yoga/YGFloatOptional.h | 1 + yoga/YGNode.cpp | 1 + yoga/Yoga.cpp | 16 +++++++++------- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/yoga/YGFloatOptional.cpp b/yoga/YGFloatOptional.cpp index 1947e9f1..5982c307 100644 --- a/yoga/YGFloatOptional.cpp +++ b/yoga/YGFloatOptional.cpp @@ -10,8 +10,16 @@ #include #include "Yoga.h" -YGFloatOptional::YGFloatOptional(const float& value) - : value_(value), isUndefined_(false) {} +YGFloatOptional::YGFloatOptional(const float& value) { + if (YGFloatIsUndefined(value)) { + isUndefined_ = true; + value_ = 0; + } else { + value_ = value; + isUndefined_ = false; + } +} + YGFloatOptional::YGFloatOptional() : value_(0), isUndefined_(true) {} const float& YGFloatOptional::getValue() const { @@ -53,3 +61,10 @@ bool YGFloatOptional::operator==(const float& val) const { bool YGFloatOptional::operator!=(const float& val) const { return !(*this == val); } + +YGFloatOptional YGFloatOptional::operator+(const YGFloatOptional& op) { + if (!isUndefined_ && !op.isUndefined_) { + return YGFloatOptional(value_ + op.value_); + } + return YGFloatOptional(); +} diff --git a/yoga/YGFloatOptional.h b/yoga/YGFloatOptional.h index 9894e40e..06ae8f15 100644 --- a/yoga/YGFloatOptional.h +++ b/yoga/YGFloatOptional.h @@ -24,6 +24,7 @@ struct YGFloatOptional { const bool& isUndefined() const; + YGFloatOptional operator+(const YGFloatOptional& op); bool operator==(const YGFloatOptional& op) const; bool operator!=(const YGFloatOptional& op) const; diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 87a92b39..d10f1941 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -167,6 +167,7 @@ float YGNode::getTrailingMargin( widthSize)); } +// TODO: Make its return type to YGFloatOptional float YGNode::getMarginForAxis( const YGFlexDirection axis, const float widthSize) const { diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 0dba6565..e10136e7 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1178,19 +1178,21 @@ static void YGConstrainMaxSizeForMode(const YGNodeRef node, const float ownerWidth, YGMeasureMode *mode, float *size) { - const float maxSize = - YGUnwrapFloatOptional(YGResolveValue( - node->getStyle().maxDimensions[dim[axis]], ownerAxisSize)) + - node->getMarginForAxis(axis, ownerWidth); + const YGFloatOptional maxSize = + YGResolveValue( + node->getStyle().maxDimensions[dim[axis]], ownerAxisSize) + + YGFloatOptional(node->getMarginForAxis(axis, ownerWidth)); switch (*mode) { case YGMeasureModeExactly: case YGMeasureModeAtMost: - *size = (YGFloatIsUndefined(maxSize) || *size < maxSize) ? *size : maxSize; + *size = (maxSize.isUndefined() || *size < maxSize.getValue()) + ? *size + : maxSize.getValue(); break; case YGMeasureModeUndefined: - if (!YGFloatIsUndefined(maxSize)) { + if (!maxSize.isUndefined()) { *mode = YGMeasureModeAtMost; - *size = maxSize; + *size = maxSize.getValue(); } break; }