Skip to content

Commit 7eb419d

Browse files
swolchokfacebook-github-bot
authored andcommitted
Tidy up YGFloatOptional
Summary: Just some convention/weird style things. `float` should be passed by value, weird use of ?: operator instead of ||. Reviewed By: priteshrnandgaonkar Differential Revision: D8804407 fbshipit-source-id: e0d67363ccde36ec5bccec7497ed0ffd364b3fcf
1 parent d756d94 commit 7eb419d

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

ReactCommon/yoga/yoga/YGFloatOptional.cpp

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
/**
2-
* Copyright (c) 2014-present, Facebook, Inc.
1+
/*
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the LICENSE
5+
* file in the root directory of this source tree.
36
*
4-
* This source code is licensed under the MIT license found in the
5-
* LICENSE file in the root directory of this source tree.
67
*/
7-
88
#include "YGFloatOptional.h"
99
#include <cstdlib>
1010
#include <iostream>
1111
#include "Yoga.h"
1212

13-
YGFloatOptional::YGFloatOptional(const float& value) {
13+
YGFloatOptional::YGFloatOptional(float value) {
1414
if (YGFloatIsUndefined(value)) {
1515
isUndefined_ = true;
1616
value_ = 0;
@@ -31,18 +31,9 @@ const float& YGFloatOptional::getValue() const {
3131
return value_;
3232
}
3333

34-
void YGFloatOptional::setValue(const float& val) {
35-
value_ = val;
36-
isUndefined_ = false;
37-
}
38-
39-
const bool& YGFloatOptional::isUndefined() const {
40-
return isUndefined_;
41-
}
42-
4334
bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
4435
if (isUndefined_ == op.isUndefined()) {
45-
return isUndefined_ ? true : value_ == op.getValue();
36+
return isUndefined_ || value_ == op.getValue();
4637
}
4738
return false;
4839
}
@@ -51,14 +42,14 @@ bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
5142
return !(*this == op);
5243
}
5344

54-
bool YGFloatOptional::operator==(const float& val) const {
45+
bool YGFloatOptional::operator==(float val) const {
5546
if (YGFloatIsUndefined(val) == isUndefined_) {
56-
return isUndefined_ ? true : val == value_;
47+
return isUndefined_ || val == value_;
5748
}
5849
return false;
5950
}
6051

61-
bool YGFloatOptional::operator!=(const float& val) const {
52+
bool YGFloatOptional::operator!=(float val) const {
6253
return !(*this == val);
6354
}
6455

@@ -84,9 +75,9 @@ bool YGFloatOptional::operator<(const YGFloatOptional& op) const {
8475
}
8576

8677
bool YGFloatOptional::operator>=(const YGFloatOptional& op) const {
87-
return *this == op ? true : *this > op;
78+
return *this == op || *this > op;
8879
}
8980

9081
bool YGFloatOptional::operator<=(const YGFloatOptional& op) const {
91-
return *this == op ? true : *this < op;
82+
return *this == op || *this < op;
9283
}
+15-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/**
2-
* Copyright (c) 2014-present, Facebook, Inc.
1+
/*
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the LICENSE
5+
* file in the root directory of this source tree.
36
*
4-
* This source code is licensed under the MIT license found in the
5-
* LICENSE file in the root directory of this source tree.
67
*/
7-
88
#pragma once
99

1010
struct YGFloatOptional {
@@ -13,7 +13,7 @@ struct YGFloatOptional {
1313
bool isUndefined_;
1414

1515
public:
16-
explicit YGFloatOptional(const float& value);
16+
explicit YGFloatOptional(float value);
1717
explicit YGFloatOptional();
1818

1919
// Program will terminate if the value of an undefined is accessed. Please
@@ -22,9 +22,14 @@ struct YGFloatOptional {
2222
const float& getValue() const;
2323

2424
// Sets the value of float optional, and thus isUndefined is assigned false.
25-
void setValue(const float& val);
25+
void setValue(float val) {
26+
value_ = val;
27+
isUndefined_ = false;
28+
}
2629

27-
const bool& isUndefined() const;
30+
bool isUndefined() const {
31+
return isUndefined_;
32+
}
2833

2934
YGFloatOptional operator+(const YGFloatOptional& op);
3035
bool operator>(const YGFloatOptional& op) const;
@@ -34,6 +39,6 @@ struct YGFloatOptional {
3439
bool operator==(const YGFloatOptional& op) const;
3540
bool operator!=(const YGFloatOptional& op) const;
3641

37-
bool operator==(const float& val) const;
38-
bool operator!=(const float& val) const;
42+
bool operator==(float val) const;
43+
bool operator!=(float val) const;
3944
};

0 commit comments

Comments
 (0)