Skip to content

Commit 34d02fb

Browse files
priteshrnandgaonkarLukeDurrant
authored andcommitted
Move equaltiy function from utils to an operator on YGFloatOptional
Reviewed By: emilsjolander Differential Revision: D7303460 fbshipit-source-id: 41ec0076ace621ec1a5bdbab00b72eea57780fff
1 parent aeb49dc commit 34d02fb

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

ReactCommon/yoga/yoga/Utils.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,3 @@ float YGFloatSanitize(const float& val) {
5757
float YGUnwrapFloatOptional(const YGFloatOptional& op) {
5858
return op.isUndefined() ? YGUndefined : op.getValue();
5959
}
60-
61-
bool YGFloatOptionalFloatEquals(
62-
const YGFloatOptional& optional,
63-
const float& val) {
64-
return YGUnwrapFloatOptional(optional) == val;
65-
}

ReactCommon/yoga/yoga/Utils.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ float YGFloatSanitize(const float& val);
9494
// TODO: Get rid off this function
9595
float YGUnwrapFloatOptional(const YGFloatOptional& op);
9696

97-
// This function returns true if val and optional both are undefined or if val
98-
// and optional.val is true, otherwise its false.
99-
bool YGFloatOptionalFloatEquals(
100-
const YGFloatOptional& optional,
101-
const float& val);
102-
10397
YGFlexDirection YGFlexDirectionCross(
10498
const YGFlexDirection flexDirection,
10599
const YGDirection direction);

ReactCommon/yoga/yoga/YGFloatOptional.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "YGFloatOptional.h"
99
#include <cstdlib>
1010
#include <iostream>
11+
#include "Yoga.h"
1112

1213
YGFloatOptional::YGFloatOptional(const float& value)
1314
: value_(value), isUndefined_(false) {}
@@ -30,3 +31,25 @@ void YGFloatOptional::setValue(const float& val) {
3031
bool YGFloatOptional::isUndefined() const {
3132
return isUndefined_;
3233
}
34+
35+
bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
36+
if (isUndefined_ == op.isUndefined()) {
37+
return isUndefined_ ? true : value_ == op.getValue();
38+
}
39+
return false;
40+
}
41+
42+
bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
43+
return !(*this == op);
44+
}
45+
46+
bool YGFloatOptional::operator==(const float& val) const {
47+
if (YGFloatIsUndefined(val) == isUndefined_) {
48+
return isUndefined_ ? true : val == value_;
49+
}
50+
return false;
51+
}
52+
53+
bool YGFloatOptional::operator!=(const float& val) const {
54+
return !(*this == val);
55+
}

ReactCommon/yoga/yoga/YGFloatOptional.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ struct YGFloatOptional {
2323
void setValue(const float& val);
2424

2525
bool isUndefined() const;
26+
27+
bool operator==(const YGFloatOptional& op) const;
28+
bool operator!=(const YGFloatOptional& op) const;
29+
30+
bool operator==(const float& val) const;
31+
bool operator!=(const float& val) const;
2632
};

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display);
801801

802802
// TODO(T26792433): Change the API to accept YGFloatOptional.
803803
void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
804-
if (!YGFloatOptionalFloatEquals(node->getStyle().flex, flex)) {
804+
if (node->getStyle().flex != flex) {
805805
YGStyle style = node->getStyle();
806806
if (YGFloatIsUndefined(flex)) {
807807
style.flex = YGFloatOptional();
@@ -821,7 +821,7 @@ float YGNodeStyleGetFlex(const YGNodeRef node) {
821821

822822
// TODO(T26792433): Change the API to accept YGFloatOptional.
823823
void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
824-
if (!YGFloatOptionalFloatEquals(node->getStyle().flexGrow, flexGrow)) {
824+
if (node->getStyle().flexGrow != flexGrow) {
825825
YGStyle style = node->getStyle();
826826
if (YGFloatIsUndefined(flexGrow)) {
827827
style.flexGrow = YGFloatOptional();
@@ -835,7 +835,7 @@ void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
835835

836836
// TODO(T26792433): Change the API to accept YGFloatOptional.
837837
void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {
838-
if (!YGFloatOptionalFloatEquals(node->getStyle().flexShrink, flexShrink)) {
838+
if (node->getStyle().flexShrink != flexShrink) {
839839
YGStyle style = node->getStyle();
840840
if (YGFloatIsUndefined(flexShrink)) {
841841
style.flexShrink = YGFloatOptional();
@@ -940,7 +940,7 @@ float YGNodeStyleGetAspectRatio(const YGNodeRef node) {
940940

941941
// TODO(T26792433): Change the API to accept YGFloatOptional.
942942
void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
943-
if (!YGFloatOptionalFloatEquals(node->getStyle().aspectRatio, aspectRatio)) {
943+
if (node->getStyle().aspectRatio != aspectRatio) {
944944
YGStyle style = node->getStyle();
945945
style.aspectRatio = YGFloatOptional(aspectRatio);
946946
node->setStyle(style);

0 commit comments

Comments
 (0)