Move equaltiy function from utils to an operator on YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7303460

fbshipit-source-id: 41ec0076ace621ec1a5bdbab00b72eea57780fff
This commit is contained in:
Pritesh Nandgaonkar 2018-04-03 14:56:31 -07:00 committed by Facebook Github Bot
parent bcd12f1e87
commit 63c073d994
5 changed files with 33 additions and 16 deletions

View File

@ -57,9 +57,3 @@ float YGFloatSanitize(const float& val) {
float YGUnwrapFloatOptional(const YGFloatOptional& op) {
return op.isUndefined() ? YGUndefined : op.getValue();
}
bool YGFloatOptionalFloatEquals(
const YGFloatOptional& optional,
const float& val) {
return YGUnwrapFloatOptional(optional) == val;
}

View File

@ -94,12 +94,6 @@ float YGFloatSanitize(const float& val);
// TODO: Get rid off this function
float YGUnwrapFloatOptional(const YGFloatOptional& op);
// This function returns true if val and optional both are undefined or if val
// and optional.val is true, otherwise its false.
bool YGFloatOptionalFloatEquals(
const YGFloatOptional& optional,
const float& val);
YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection,
const YGDirection direction);

View File

@ -8,6 +8,7 @@
#include "YGFloatOptional.h"
#include <cstdlib>
#include <iostream>
#include "Yoga.h"
YGFloatOptional::YGFloatOptional(const float& value)
: value_(value), isUndefined_(false) {}
@ -30,3 +31,25 @@ void YGFloatOptional::setValue(const float& val) {
bool YGFloatOptional::isUndefined() const {
return isUndefined_;
}
bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
if (isUndefined_ == op.isUndefined()) {
return isUndefined_ ? true : value_ == op.getValue();
}
return false;
}
bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
return !(*this == op);
}
bool YGFloatOptional::operator==(const float& val) const {
if (YGFloatIsUndefined(val) == isUndefined_) {
return isUndefined_ ? true : val == value_;
}
return false;
}
bool YGFloatOptional::operator!=(const float& val) const {
return !(*this == val);
}

View File

@ -23,4 +23,10 @@ struct YGFloatOptional {
void setValue(const float& val);
bool isUndefined() const;
bool operator==(const YGFloatOptional& op) const;
bool operator!=(const YGFloatOptional& op) const;
bool operator==(const float& val) const;
bool operator!=(const float& val) const;
};

View File

@ -801,7 +801,7 @@ YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display);
// TODO(T26792433): Change the API to accept YGFloatOptional.
void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
if (!YGFloatOptionalFloatEquals(node->getStyle().flex, flex)) {
if (node->getStyle().flex != flex) {
YGStyle style = node->getStyle();
if (YGFloatIsUndefined(flex)) {
style.flex = YGFloatOptional();
@ -821,7 +821,7 @@ float YGNodeStyleGetFlex(const YGNodeRef node) {
// TODO(T26792433): Change the API to accept YGFloatOptional.
void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
if (!YGFloatOptionalFloatEquals(node->getStyle().flexGrow, flexGrow)) {
if (node->getStyle().flexGrow != flexGrow) {
YGStyle style = node->getStyle();
if (YGFloatIsUndefined(flexGrow)) {
style.flexGrow = YGFloatOptional();
@ -835,7 +835,7 @@ void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
// TODO(T26792433): Change the API to accept YGFloatOptional.
void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {
if (!YGFloatOptionalFloatEquals(node->getStyle().flexShrink, flexShrink)) {
if (node->getStyle().flexShrink != flexShrink) {
YGStyle style = node->getStyle();
if (YGFloatIsUndefined(flexShrink)) {
style.flexShrink = YGFloatOptional();
@ -940,7 +940,7 @@ float YGNodeStyleGetAspectRatio(const YGNodeRef node) {
// TODO(T26792433): Change the API to accept YGFloatOptional.
void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
if (!YGFloatOptionalFloatEquals(node->getStyle().aspectRatio, aspectRatio)) {
if (node->getStyle().aspectRatio != aspectRatio) {
YGStyle style = node->getStyle();
style.aspectRatio = YGFloatOptional(aspectRatio);
node->setStyle(style);