Summary: Changed NaN with large number to support `-ffast-math` compiler flag.For `-ffast-math` to work, all floating point numbers should be finite. Reason for not going with `FLT_MAX`, is that, it may cause number overflow during math operations. So thats why I opted for big number smaller than `FLT_MAX`. Earlier we used NaN, while NaN is involved in comparision the comparision operator behaves differently, it always returns false. Also operators like, fmaxf,fminf etc. have wierd beahviours. This diff takes care of those things as far as possible, and all tests are passing. Running ./instrumentation_tests/run instrumentation_tests/com/facebook/feed/ctacoalescing:ctacoalescing --class AttachmentCallToActionSelectorBenchmarkTest --benchmark --extra-arg iterations=100 shows the perf gain of 13-15% Reviewed By: emilsjolander Differential Revision: D6969537 fbshipit-source-id: bdc09eaf703e0d313ca65c25a4fb44c99203d9bf
111 lines
3.4 KiB
C++
111 lines
3.4 KiB
C++
/**
|
|
* 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.
|
|
*/
|
|
|
|
#pragma once
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <cmath>
|
|
#include <vector>
|
|
#include "Yoga.h"
|
|
|
|
using YGVector = std::vector<YGNodeRef>;
|
|
|
|
YG_EXTERN_C_BEGIN
|
|
|
|
WIN_EXPORT float YGRoundValueToPixelGrid(const float value,
|
|
const float pointScaleFactor,
|
|
const bool forceCeil,
|
|
const bool forceFloor);
|
|
|
|
YG_EXTERN_C_END
|
|
|
|
extern const std::array<YGEdge, 4> trailing;
|
|
extern const std::array<YGEdge, 4> leading;
|
|
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
|
extern const YGValue YGValueUndefined;
|
|
extern const YGValue YGValueAuto;
|
|
extern const YGValue YGValueZero;
|
|
|
|
template <std::size_t size>
|
|
bool YGValueArrayEqual(
|
|
const std::array<YGValue, size> val1,
|
|
const std::array<YGValue, size> val2) {
|
|
bool areEqual = true;
|
|
for (uint32_t i = 0; i < size && areEqual; ++i) {
|
|
areEqual = YGValueEqual(val1[i], val2[i]);
|
|
}
|
|
return areEqual;
|
|
}
|
|
|
|
struct YGCachedMeasurement {
|
|
float availableWidth;
|
|
float availableHeight;
|
|
YGMeasureMode widthMeasureMode;
|
|
YGMeasureMode heightMeasureMode;
|
|
|
|
float computedWidth;
|
|
float computedHeight;
|
|
|
|
YGCachedMeasurement()
|
|
: availableWidth(0),
|
|
availableHeight(0),
|
|
widthMeasureMode((YGMeasureMode)-1),
|
|
heightMeasureMode((YGMeasureMode)-1),
|
|
computedWidth(-1),
|
|
computedHeight(-1) {}
|
|
|
|
bool operator==(YGCachedMeasurement measurement) const {
|
|
bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
|
|
heightMeasureMode == measurement.heightMeasureMode;
|
|
|
|
if (!YGFloatIsUndefined(availableWidth) ||
|
|
!YGFloatIsUndefined(measurement.availableWidth)) {
|
|
isEqual = isEqual && availableWidth == measurement.availableWidth;
|
|
}
|
|
if (!YGFloatIsUndefined(availableHeight) ||
|
|
!YGFloatIsUndefined(measurement.availableHeight)) {
|
|
isEqual = isEqual && availableHeight == measurement.availableHeight;
|
|
}
|
|
if (!YGFloatIsUndefined(computedWidth) ||
|
|
!YGFloatIsUndefined(measurement.computedWidth)) {
|
|
isEqual = isEqual && computedWidth == measurement.computedWidth;
|
|
}
|
|
if (!YGFloatIsUndefined(computedHeight) ||
|
|
!YGFloatIsUndefined(measurement.computedHeight)) {
|
|
isEqual = isEqual && computedHeight == measurement.computedHeight;
|
|
}
|
|
|
|
return isEqual;
|
|
}
|
|
};
|
|
|
|
// This value was chosen based on empiracle data. Even the most complicated
|
|
// layouts should not require more than 16 entries to fit within the cache.
|
|
#define YG_MAX_CACHED_RESULT_COUNT 16
|
|
|
|
struct YGConfig {
|
|
bool experimentalFeatures[YGExperimentalFeatureCount + 1];
|
|
bool useWebDefaults;
|
|
bool useLegacyStretchBehaviour;
|
|
bool shouldDiffLayoutWithoutLegacyStretchBehaviour;
|
|
float pointScaleFactor;
|
|
YGLogger logger;
|
|
YGNodeClonedFunc cloneNodeCallback;
|
|
void* context;
|
|
};
|
|
|
|
static const float kDefaultFlexGrow = 0.0f;
|
|
static const float kDefaultFlexShrink = 0.0f;
|
|
static const float kWebDefaultFlexShrink = 1.0f;
|
|
|
|
extern bool YGFloatsEqual(const float a, const float b);
|
|
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
|
extern const YGValue* YGComputedEdgeValue(
|
|
const std::array<YGValue, YGEdgeCount>& edges,
|
|
const YGEdge edge,
|
|
const YGValue* const defaultValue);
|