From e9e2ae28e046758d4e457defdba74955a4b38a8c Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 12 Jul 2018 08:40:52 -0700 Subject: [PATCH] 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 --- yoga/YGFloatOptional.cpp | 33 ++++++++++++--------------------- yoga/YGFloatOptional.h | 25 +++++++++++++++---------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/yoga/YGFloatOptional.cpp b/yoga/YGFloatOptional.cpp index 00bfc71e..ceee1dc2 100644 --- a/yoga/YGFloatOptional.cpp +++ b/yoga/YGFloatOptional.cpp @@ -1,16 +1,16 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. +/* + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. */ - #include "YGFloatOptional.h" #include #include #include "Yoga.h" -YGFloatOptional::YGFloatOptional(const float& value) { +YGFloatOptional::YGFloatOptional(float value) { if (YGFloatIsUndefined(value)) { isUndefined_ = true; value_ = 0; @@ -31,18 +31,9 @@ const float& YGFloatOptional::getValue() const { return value_; } -void YGFloatOptional::setValue(const float& val) { - value_ = val; - isUndefined_ = false; -} - -const bool& YGFloatOptional::isUndefined() const { - return isUndefined_; -} - bool YGFloatOptional::operator==(const YGFloatOptional& op) const { if (isUndefined_ == op.isUndefined()) { - return isUndefined_ ? true : value_ == op.getValue(); + return isUndefined_ || value_ == op.getValue(); } return false; } @@ -51,14 +42,14 @@ bool YGFloatOptional::operator!=(const YGFloatOptional& op) const { return !(*this == op); } -bool YGFloatOptional::operator==(const float& val) const { +bool YGFloatOptional::operator==(float val) const { if (YGFloatIsUndefined(val) == isUndefined_) { - return isUndefined_ ? true : val == value_; + return isUndefined_ || val == value_; } return false; } -bool YGFloatOptional::operator!=(const float& val) const { +bool YGFloatOptional::operator!=(float val) const { return !(*this == val); } @@ -84,9 +75,9 @@ bool YGFloatOptional::operator<(const YGFloatOptional& op) const { } bool YGFloatOptional::operator>=(const YGFloatOptional& op) const { - return *this == op ? true : *this > op; + return *this == op || *this > op; } bool YGFloatOptional::operator<=(const YGFloatOptional& op) const { - return *this == op ? true : *this < op; + return *this == op || *this < op; } diff --git a/yoga/YGFloatOptional.h b/yoga/YGFloatOptional.h index 21af2a80..d426d849 100644 --- a/yoga/YGFloatOptional.h +++ b/yoga/YGFloatOptional.h @@ -1,10 +1,10 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. +/* + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. */ - #pragma once struct YGFloatOptional { @@ -13,7 +13,7 @@ struct YGFloatOptional { bool isUndefined_; public: - explicit YGFloatOptional(const float& value); + explicit YGFloatOptional(float value); explicit YGFloatOptional(); // Program will terminate if the value of an undefined is accessed. Please @@ -22,9 +22,14 @@ struct YGFloatOptional { const float& getValue() const; // Sets the value of float optional, and thus isUndefined is assigned false. - void setValue(const float& val); + void setValue(float val) { + value_ = val; + isUndefined_ = false; + } - const bool& isUndefined() const; + bool isUndefined() const { + return isUndefined_; + } YGFloatOptional operator+(const YGFloatOptional& op); bool operator>(const YGFloatOptional& op) const; @@ -34,6 +39,6 @@ struct YGFloatOptional { bool operator==(const YGFloatOptional& op) const; bool operator!=(const YGFloatOptional& op) const; - bool operator==(const float& val) const; - bool operator!=(const float& val) const; + bool operator==(float val) const; + bool operator!=(float val) const; };