Skip to content

Commit

Permalink
Tidy up YGFloatOptional
Browse files Browse the repository at this point in the history
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
  • Loading branch information
swolchok authored and facebook-github-bot committed Jul 12, 2018
1 parent 4ed3dd4 commit e9e2ae2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
33 changes: 12 additions & 21 deletions yoga/YGFloatOptional.cpp
Original file line number Diff line number Diff line change
@@ -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 <cstdlib>
#include <iostream>
#include "Yoga.h"

YGFloatOptional::YGFloatOptional(const float& value) {
YGFloatOptional::YGFloatOptional(float value) {
if (YGFloatIsUndefined(value)) {
isUndefined_ = true;
value_ = 0;
Expand All @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -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;
}
25 changes: 15 additions & 10 deletions yoga/YGFloatOptional.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
};

0 comments on commit e9e2ae2

Please sign in to comment.