Make YGFloatIsUndefined
inlineable
Summary: @public Makes `YGFloatIsUndefined` inlineable Reviewed By: swolchok Differential Revision: D8875520 fbshipit-source-id: 7ac653e002512b1a8d5f9c04e0a21381aeb02e67
This commit is contained in:
committed by
Facebook Github Bot
parent
1b32c4f054
commit
c1a9f6120a
@@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
using namespace facebook;
|
||||||
|
|
||||||
YGFlexDirection YGFlexDirectionCross(
|
YGFlexDirection YGFlexDirectionCross(
|
||||||
const YGFlexDirection flexDirection,
|
const YGFlexDirection flexDirection,
|
||||||
const YGDirection direction) {
|
const YGDirection direction) {
|
||||||
@@ -16,18 +18,18 @@ YGFlexDirection YGFlexDirectionCross(
|
|||||||
}
|
}
|
||||||
|
|
||||||
float YGFloatMax(const float a, const float b) {
|
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 fmaxf(a, b);
|
||||||
}
|
}
|
||||||
return YGFloatIsUndefined(a) ? b : a;
|
return yoga::isUndefined(a) ? b : a;
|
||||||
}
|
}
|
||||||
|
|
||||||
float YGFloatMin(const float a, const float b) {
|
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 fminf(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
return YGFloatIsUndefined(a) ? b : a;
|
return yoga::isUndefined(a) ? b : a;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGValueEqual(const YGValue a, const YGValue b) {
|
bool YGValueEqual(const YGValue a, const YGValue b) {
|
||||||
@@ -36,7 +38,7 @@ bool YGValueEqual(const YGValue a, const YGValue b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (a.unit == YGUnitUndefined ||
|
if (a.unit == YGUnitUndefined ||
|
||||||
(YGFloatIsUndefined(a.value) && YGFloatIsUndefined(b.value))) {
|
(yoga::isUndefined(a.value) && yoga::isUndefined(b.value))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,14 +46,14 @@ bool YGValueEqual(const YGValue a, const YGValue b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool YGFloatsEqual(const float a, const float 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 fabs(a - b) < 0.0001f;
|
||||||
}
|
}
|
||||||
return YGFloatIsUndefined(a) && YGFloatIsUndefined(b);
|
return yoga::isUndefined(a) && yoga::isUndefined(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
float YGFloatSanitize(const float& val) {
|
float YGFloatSanitize(const float& val) {
|
||||||
return YGFloatIsUndefined(val) ? 0 : val;
|
return yoga::isUndefined(val) ? 0 : val;
|
||||||
}
|
}
|
||||||
|
|
||||||
float YGUnwrapFloatOptional(const YGFloatOptional& op) {
|
float YGUnwrapFloatOptional(const YGFloatOptional& op) {
|
||||||
|
@@ -9,9 +9,12 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Yoga.h"
|
#include "Yoga.h"
|
||||||
|
#include "Yoga-internal.h"
|
||||||
|
|
||||||
|
using namespace facebook;
|
||||||
|
|
||||||
YGFloatOptional::YGFloatOptional(float value) {
|
YGFloatOptional::YGFloatOptional(float value) {
|
||||||
if (YGFloatIsUndefined(value)) {
|
if (yoga::isUndefined(value)) {
|
||||||
isUndefined_ = true;
|
isUndefined_ = true;
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -41,7 +44,7 @@ bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool YGFloatOptional::operator==(float val) const {
|
bool YGFloatOptional::operator==(float val) const {
|
||||||
if (YGFloatIsUndefined(val) == isUndefined_) {
|
if (yoga::isUndefined(val) == isUndefined_) {
|
||||||
return isUndefined_ || val == value_;
|
return isUndefined_ || val == value_;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
#include "YGLayout.h"
|
#include "YGLayout.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
using namespace facebook;
|
||||||
|
|
||||||
const std::array<float, 2> kYGDefaultDimensionValues = {
|
const std::array<float, 2> kYGDefaultDimensionValues = {
|
||||||
{YGUndefined, YGUndefined}};
|
{YGUndefined, YGUndefined}};
|
||||||
|
|
||||||
@@ -46,13 +48,13 @@ bool YGLayout::operator==(YGLayout layout) const {
|
|||||||
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
|
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!YGFloatIsUndefined(measuredDimensions[0]) ||
|
if (!yoga::isUndefined(measuredDimensions[0]) ||
|
||||||
!YGFloatIsUndefined(layout.measuredDimensions[0])) {
|
!yoga::isUndefined(layout.measuredDimensions[0])) {
|
||||||
isEqual =
|
isEqual =
|
||||||
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
|
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(measuredDimensions[1]) ||
|
if (!yoga::isUndefined(measuredDimensions[1]) ||
|
||||||
!YGFloatIsUndefined(layout.measuredDimensions[1])) {
|
!yoga::isUndefined(layout.measuredDimensions[1])) {
|
||||||
isEqual =
|
isEqual =
|
||||||
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
|
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
using namespace facebook;
|
||||||
|
|
||||||
YGFloatOptional YGNode::getLeadingPosition(
|
YGFloatOptional YGNode::getLeadingPosition(
|
||||||
const YGFlexDirection& axis,
|
const YGFlexDirection& axis,
|
||||||
const float& axisSize) const {
|
const float& axisSize) const {
|
||||||
@@ -500,7 +502,7 @@ bool YGNode::isNodeFlexible() {
|
|||||||
float YGNode::getLeadingBorder(const YGFlexDirection& axis) const {
|
float YGNode::getLeadingBorder(const YGFlexDirection& axis) const {
|
||||||
if (YGFlexDirectionIsRow(axis) &&
|
if (YGFlexDirectionIsRow(axis) &&
|
||||||
style_.border[YGEdgeStart].unit != YGUnitUndefined &&
|
style_.border[YGEdgeStart].unit != YGUnitUndefined &&
|
||||||
!YGFloatIsUndefined(style_.border[YGEdgeStart].value) &&
|
!yoga::isUndefined(style_.border[YGEdgeStart].value) &&
|
||||||
style_.border[YGEdgeStart].value >= 0.0f) {
|
style_.border[YGEdgeStart].value >= 0.0f) {
|
||||||
return style_.border[YGEdgeStart].value;
|
return style_.border[YGEdgeStart].value;
|
||||||
}
|
}
|
||||||
@@ -513,7 +515,7 @@ float YGNode::getLeadingBorder(const YGFlexDirection& axis) const {
|
|||||||
float YGNode::getTrailingBorder(const YGFlexDirection& flexDirection) const {
|
float YGNode::getTrailingBorder(const YGFlexDirection& flexDirection) const {
|
||||||
if (YGFlexDirectionIsRow(flexDirection) &&
|
if (YGFlexDirectionIsRow(flexDirection) &&
|
||||||
style_.border[YGEdgeEnd].unit != YGUnitUndefined &&
|
style_.border[YGEdgeEnd].unit != YGUnitUndefined &&
|
||||||
!YGFloatIsUndefined(style_.border[YGEdgeEnd].value) &&
|
!yoga::isUndefined(style_.border[YGEdgeEnd].value) &&
|
||||||
style_.border[YGEdgeEnd].value >= 0.0f) {
|
style_.border[YGEdgeEnd].value >= 0.0f) {
|
||||||
return style_.border[YGEdgeEnd].value;
|
return style_.border[YGEdgeEnd].value;
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,26 @@ WIN_EXPORT float YGRoundValueToPixelGrid(
|
|||||||
|
|
||||||
YG_EXTERN_C_END
|
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> trailing;
|
||||||
extern const std::array<YGEdge, 4> leading;
|
extern const std::array<YGEdge, 4> leading;
|
||||||
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
||||||
@@ -63,20 +83,20 @@ struct YGCachedMeasurement {
|
|||||||
bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
|
bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
|
||||||
heightMeasureMode == measurement.heightMeasureMode;
|
heightMeasureMode == measurement.heightMeasureMode;
|
||||||
|
|
||||||
if (!YGFloatIsUndefined(availableWidth) ||
|
if (!yoga::isUndefined(availableWidth) ||
|
||||||
!YGFloatIsUndefined(measurement.availableWidth)) {
|
!yoga::isUndefined(measurement.availableWidth)) {
|
||||||
isEqual = isEqual && availableWidth == measurement.availableWidth;
|
isEqual = isEqual && availableWidth == measurement.availableWidth;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(availableHeight) ||
|
if (!yoga::isUndefined(availableHeight) ||
|
||||||
!YGFloatIsUndefined(measurement.availableHeight)) {
|
!yoga::isUndefined(measurement.availableHeight)) {
|
||||||
isEqual = isEqual && availableHeight == measurement.availableHeight;
|
isEqual = isEqual && availableHeight == measurement.availableHeight;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(computedWidth) ||
|
if (!yoga::isUndefined(computedWidth) ||
|
||||||
!YGFloatIsUndefined(measurement.computedWidth)) {
|
!yoga::isUndefined(measurement.computedWidth)) {
|
||||||
isEqual = isEqual && computedWidth == measurement.computedWidth;
|
isEqual = isEqual && computedWidth == measurement.computedWidth;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(computedHeight) ||
|
if (!yoga::isUndefined(computedHeight) ||
|
||||||
!YGFloatIsUndefined(measurement.computedHeight)) {
|
!yoga::isUndefined(measurement.computedHeight)) {
|
||||||
isEqual = isEqual && computedHeight == measurement.computedHeight;
|
isEqual = isEqual && computedHeight == measurement.computedHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -104,15 +104,7 @@ static int YGDefaultLog(const YGConfigRef config,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool YGFloatIsUndefined(const float value) {
|
bool YGFloatIsUndefined(const float value) {
|
||||||
// Value of a float in the case of it being not defined is 10.1E20. Earlier
|
return facebook::yoga::isUndefined(value);
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const YGValue* YGComputedEdgeValue(
|
const YGValue* YGComputedEdgeValue(
|
||||||
|
Reference in New Issue
Block a user