Store YGFloatOptional in 32 bits

Summary:
@public

After removing `-ffast-math`, `NaN` can again be used to represent `undefined`. That allows us to remove the additional flag from `YGFloatOptional`, and reduce memory usage.

Reviewed By: SidharthGuglani

Differential Revision: D13209157

fbshipit-source-id: 21b83c837a78f924a4ec23a9236ca2440b3c8606
This commit is contained in:
David Aurelio
2018-12-06 07:35:08 -08:00
committed by Facebook Github Bot
parent ed5c5a799f
commit ed3b54b603
4 changed files with 192 additions and 58 deletions

View File

@@ -7,23 +7,13 @@
#include "YGFloatOptional.h"
#include <cstdlib>
#include <iostream>
#include "Yoga.h"
#include "Yoga-internal.h"
#include "Yoga.h"
using namespace facebook;
YGFloatOptional::YGFloatOptional(float value) {
if (yoga::isUndefined(value)) {
isUndefined_ = true;
value_ = 0;
} else {
value_ = value;
isUndefined_ = false;
}
}
float YGFloatOptional::getValue() const {
if (isUndefined_) {
if (isUndefined()) {
// Abort, accessing a value of an undefined float optional
std::cerr << "Tried to get value of an undefined YGFloatOptional\n";
std::exit(EXIT_FAILURE);
@@ -31,53 +21,38 @@ float YGFloatOptional::getValue() const {
return value_;
}
bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
if (isUndefined_ == op.isUndefined()) {
return isUndefined_ || value_ == op.getValue();
}
return false;
bool YGFloatOptional::operator==(YGFloatOptional op) const {
return value_ == op.value_ || (isUndefined() && op.isUndefined());
}
bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
bool YGFloatOptional::operator!=(YGFloatOptional op) const {
return !(*this == op);
}
bool YGFloatOptional::operator==(float val) const {
if (yoga::isUndefined(val) == isUndefined_) {
return isUndefined_ || val == value_;
}
return false;
return value_ == val || (isUndefined() && yoga::isUndefined(val));
}
bool YGFloatOptional::operator!=(float val) const {
return !(*this == val);
}
YGFloatOptional YGFloatOptional::operator+(const YGFloatOptional& op) {
if (!isUndefined_ && !op.isUndefined_) {
return YGFloatOptional(value_ + op.value_);
}
return YGFloatOptional();
YGFloatOptional YGFloatOptional::operator+(YGFloatOptional op) const {
return YGFloatOptional{value_ + op.value_};
}
bool YGFloatOptional::operator>(const YGFloatOptional& op) const {
if (isUndefined_ || op.isUndefined_) {
return false;
}
bool YGFloatOptional::operator>(YGFloatOptional op) const {
return value_ > op.value_;
}
bool YGFloatOptional::operator<(const YGFloatOptional& op) const {
if (isUndefined_ || op.isUndefined_) {
return false;
}
bool YGFloatOptional::operator<(YGFloatOptional op) const {
return value_ < op.value_;
}
bool YGFloatOptional::operator>=(const YGFloatOptional& op) const {
return *this == op || *this > op;
bool YGFloatOptional::operator>=(YGFloatOptional op) const {
return *this > op || *this == op;
}
bool YGFloatOptional::operator<=(const YGFloatOptional& op) const {
return *this == op || *this < op;
bool YGFloatOptional::operator<=(YGFloatOptional op) const {
return *this < op || *this == op;
}