Make `YGFloatIsUndefined` inlineable
Summary: @public Makes `YGFloatIsUndefined` inlineable Reviewed By: swolchok Differential Revision: D8875520 fbshipit-source-id: 7ac653e002512b1a8d5f9c04e0a21381aeb02e67
This commit is contained in:
parent
b330579204
commit
04aaa01991
|
@ -7,6 +7,8 @@
|
|||
*/
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
YGFlexDirection YGFlexDirectionCross(
|
||||
const YGFlexDirection flexDirection,
|
||||
const YGDirection direction) {
|
||||
|
@ -16,18 +18,18 @@ YGFlexDirection YGFlexDirectionCross(
|
|||
}
|
||||
|
||||
float YGFloatMax(const float a, const float b) {
|
||||
if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
|
||||
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
|
||||
return fmaxf(a, b);
|
||||
}
|
||||
return YGFloatIsUndefined(a) ? b : a;
|
||||
return yoga::isUndefined(a) ? b : a;
|
||||
}
|
||||
|
||||
float YGFloatMin(const float a, const float b) {
|
||||
if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
|
||||
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
|
||||
return fminf(a, b);
|
||||
}
|
||||
|
||||
return YGFloatIsUndefined(a) ? b : a;
|
||||
return yoga::isUndefined(a) ? b : a;
|
||||
}
|
||||
|
||||
bool YGValueEqual(const YGValue a, const YGValue b) {
|
||||
|
@ -36,7 +38,7 @@ bool YGValueEqual(const YGValue a, const YGValue b) {
|
|||
}
|
||||
|
||||
if (a.unit == YGUnitUndefined ||
|
||||
(YGFloatIsUndefined(a.value) && YGFloatIsUndefined(b.value))) {
|
||||
(yoga::isUndefined(a.value) && yoga::isUndefined(b.value))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -44,14 +46,14 @@ bool YGValueEqual(const YGValue a, const YGValue b) {
|
|||
}
|
||||
|
||||
bool YGFloatsEqual(const float a, const float b) {
|
||||
if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
|
||||
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
|
||||
return fabs(a - b) < 0.0001f;
|
||||
}
|
||||
return YGFloatIsUndefined(a) && YGFloatIsUndefined(b);
|
||||
return yoga::isUndefined(a) && yoga::isUndefined(b);
|
||||
}
|
||||
|
||||
float YGFloatSanitize(const float& val) {
|
||||
return YGFloatIsUndefined(val) ? 0 : val;
|
||||
return yoga::isUndefined(val) ? 0 : val;
|
||||
}
|
||||
|
||||
float YGUnwrapFloatOptional(const YGFloatOptional& op) {
|
||||
|
|
|
@ -9,9 +9,12 @@
|
|||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include "Yoga.h"
|
||||
#include "Yoga-internal.h"
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
YGFloatOptional::YGFloatOptional(float value) {
|
||||
if (YGFloatIsUndefined(value)) {
|
||||
if (yoga::isUndefined(value)) {
|
||||
isUndefined_ = true;
|
||||
value_ = 0;
|
||||
} else {
|
||||
|
@ -41,7 +44,7 @@ bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
|
|||
}
|
||||
|
||||
bool YGFloatOptional::operator==(float val) const {
|
||||
if (YGFloatIsUndefined(val) == isUndefined_) {
|
||||
if (yoga::isUndefined(val) == isUndefined_) {
|
||||
return isUndefined_ || val == value_;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "YGLayout.h"
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
const std::array<float, 2> kYGDefaultDimensionValues = {
|
||||
{YGUndefined, YGUndefined}};
|
||||
|
||||
|
@ -46,13 +48,13 @@ bool YGLayout::operator==(YGLayout layout) const {
|
|||
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
|
||||
}
|
||||
|
||||
if (!YGFloatIsUndefined(measuredDimensions[0]) ||
|
||||
!YGFloatIsUndefined(layout.measuredDimensions[0])) {
|
||||
if (!yoga::isUndefined(measuredDimensions[0]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions[0])) {
|
||||
isEqual =
|
||||
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
|
||||
}
|
||||
if (!YGFloatIsUndefined(measuredDimensions[1]) ||
|
||||
!YGFloatIsUndefined(layout.measuredDimensions[1])) {
|
||||
if (!yoga::isUndefined(measuredDimensions[1]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions[1])) {
|
||||
isEqual =
|
||||
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include <iostream>
|
||||
#include "Utils.h"
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
YGFloatOptional YGNode::getLeadingPosition(
|
||||
const YGFlexDirection& axis,
|
||||
const float& axisSize) const {
|
||||
|
@ -500,7 +502,7 @@ bool YGNode::isNodeFlexible() {
|
|||
float YGNode::getLeadingBorder(const YGFlexDirection& axis) const {
|
||||
if (YGFlexDirectionIsRow(axis) &&
|
||||
style_.border[YGEdgeStart].unit != YGUnitUndefined &&
|
||||
!YGFloatIsUndefined(style_.border[YGEdgeStart].value) &&
|
||||
!yoga::isUndefined(style_.border[YGEdgeStart].value) &&
|
||||
style_.border[YGEdgeStart].value >= 0.0f) {
|
||||
return style_.border[YGEdgeStart].value;
|
||||
}
|
||||
|
@ -513,7 +515,7 @@ float YGNode::getLeadingBorder(const YGFlexDirection& axis) const {
|
|||
float YGNode::getTrailingBorder(const YGFlexDirection& flexDirection) const {
|
||||
if (YGFlexDirectionIsRow(flexDirection) &&
|
||||
style_.border[YGEdgeEnd].unit != YGUnitUndefined &&
|
||||
!YGFloatIsUndefined(style_.border[YGEdgeEnd].value) &&
|
||||
!yoga::isUndefined(style_.border[YGEdgeEnd].value) &&
|
||||
style_.border[YGEdgeEnd].value >= 0.0f) {
|
||||
return style_.border[YGEdgeEnd].value;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,26 @@ WIN_EXPORT float YGRoundValueToPixelGrid(
|
|||
|
||||
YG_EXTERN_C_END
|
||||
|
||||
namespace facebook {
|
||||
namespace yoga {
|
||||
|
||||
inline bool isUndefined(float value) {
|
||||
// Value of a float in the case of it being not defined is 10.1E20. Earlier
|
||||
// it used to be NAN, the benefit of which was that if NAN is involved in any
|
||||
// mathematical expression the result was NAN. But since we want to have
|
||||
// `-ffast-math` flag being used by compiler which assumes that the floating
|
||||
// point values are not NAN and Inf, we represent YGUndefined as 10.1E20. But
|
||||
// now if YGUndefined is involved in any mathematical operations this
|
||||
// value(10.1E20) would change. So the following check makes sure that if the
|
||||
// value is outside a range (-10E8, 10E8) then it is undefined.
|
||||
return value >= 10E8 || value <= -10E8;
|
||||
}
|
||||
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
extern const std::array<YGEdge, 4> trailing;
|
||||
extern const std::array<YGEdge, 4> leading;
|
||||
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
||||
|
@ -63,20 +83,20 @@ struct YGCachedMeasurement {
|
|||
bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
|
||||
heightMeasureMode == measurement.heightMeasureMode;
|
||||
|
||||
if (!YGFloatIsUndefined(availableWidth) ||
|
||||
!YGFloatIsUndefined(measurement.availableWidth)) {
|
||||
if (!yoga::isUndefined(availableWidth) ||
|
||||
!yoga::isUndefined(measurement.availableWidth)) {
|
||||
isEqual = isEqual && availableWidth == measurement.availableWidth;
|
||||
}
|
||||
if (!YGFloatIsUndefined(availableHeight) ||
|
||||
!YGFloatIsUndefined(measurement.availableHeight)) {
|
||||
if (!yoga::isUndefined(availableHeight) ||
|
||||
!yoga::isUndefined(measurement.availableHeight)) {
|
||||
isEqual = isEqual && availableHeight == measurement.availableHeight;
|
||||
}
|
||||
if (!YGFloatIsUndefined(computedWidth) ||
|
||||
!YGFloatIsUndefined(measurement.computedWidth)) {
|
||||
if (!yoga::isUndefined(computedWidth) ||
|
||||
!yoga::isUndefined(measurement.computedWidth)) {
|
||||
isEqual = isEqual && computedWidth == measurement.computedWidth;
|
||||
}
|
||||
if (!YGFloatIsUndefined(computedHeight) ||
|
||||
!YGFloatIsUndefined(measurement.computedHeight)) {
|
||||
if (!yoga::isUndefined(computedHeight) ||
|
||||
!yoga::isUndefined(measurement.computedHeight)) {
|
||||
isEqual = isEqual && computedHeight == measurement.computedHeight;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,15 +104,7 @@ static int YGDefaultLog(const YGConfigRef config,
|
|||
#endif
|
||||
|
||||
bool YGFloatIsUndefined(const float value) {
|
||||
// Value of a float in the case of it being not defined is 10.1E20. Earlier
|
||||
// it used to be NAN, the benefit of which was that if NAN is involved in any
|
||||
// mathematical expression the result was NAN. But since we want to have
|
||||
// `-ffast-math` flag being used by compiler which assumes that the floating
|
||||
// point values are not NAN and Inf, we represent YGUndefined as 10.1E20. But
|
||||
// now if YGUndefined is involved in any mathematical operations this
|
||||
// value(10.1E20) would change. So the following check makes sure that if the
|
||||
// value is outside a range (-10E8, 10E8) then it is undefined.
|
||||
return value >= 10E8 || value <= -10E8;
|
||||
return facebook::yoga::isUndefined(value);
|
||||
}
|
||||
|
||||
const YGValue* YGComputedEdgeValue(
|
||||
|
|
Loading…
Reference in New Issue