Replaced default constructors with member assignments

Reviewed By: davidaurelio

Differential Revision: D10466125

fbshipit-source-id: ed92d1e054a8b5b9a6c8c09035173b11da45c368
This commit is contained in:
Sidharth Guglani
2018-10-25 08:02:04 -07:00
committed by Facebook Github Bot
parent ba9bd4eae3
commit fad2ee1a64
7 changed files with 75 additions and 133 deletions

View File

@@ -7,16 +7,4 @@
*/
#include "YGConfig.h"
const std::array<bool, YGExperimentalFeatureCount>
kYGDefaultExperimentalFeatures = {{false}};
YGConfig::YGConfig(YGLogger logger)
: experimentalFeatures(kYGDefaultExperimentalFeatures),
useWebDefaults(false),
useLegacyStretchBehaviour(false),
shouldDiffLayoutWithoutLegacyStretchBehaviour(false),
pointScaleFactor(1.0f),
logger(logger),
cloneNodeCallback(nullptr),
context(nullptr),
printTree(false) {}
YGConfig::YGConfig(YGLogger logger) : logger(logger) {}

View File

@@ -10,15 +10,15 @@
#include "Yoga.h"
struct YGConfig {
std::array<bool, YGExperimentalFeatureCount> experimentalFeatures;
bool useWebDefaults;
bool useLegacyStretchBehaviour;
bool shouldDiffLayoutWithoutLegacyStretchBehaviour;
float pointScaleFactor;
std::array<bool, YGExperimentalFeatureCount> experimentalFeatures = {};
bool useWebDefaults = false;
bool useLegacyStretchBehaviour = false;
bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false;
float pointScaleFactor = 1.0f;
YGLogger logger;
YGCloneNodeFunc cloneNodeCallback;
void* context;
bool printTree;
YGCloneNodeFunc cloneNodeCallback = nullptr;
void* context = nullptr;
bool printTree = false;
YGConfig(YGLogger logger);
};

View File

@@ -9,12 +9,12 @@
struct YGFloatOptional {
private:
float value_;
bool isUndefined_;
float value_ = 0;
bool isUndefined_ = true;
public:
explicit YGFloatOptional(float value);
explicit YGFloatOptional() : value_(0), isUndefined_(true) {}
YGFloatOptional() = default;
// Program will terminate if the value of an undefined is accessed. Please
// make sure to check if the optional is defined before calling this function.

View File

@@ -10,28 +10,6 @@
using namespace facebook;
const std::array<float, 2> kYGDefaultDimensionValues = {
{YGUndefined, YGUndefined}};
YGLayout::YGLayout()
: position(),
dimensions(kYGDefaultDimensionValues),
margin(),
border(),
padding(),
direction(YGDirectionInherit),
computedFlexBasisGeneration(0),
computedFlexBasis(YGFloatOptional()),
hadOverflow(false),
generationCount(0),
lastOwnerDirection((YGDirection)-1),
nextCachedMeasurementsIndex(0),
cachedMeasurements(),
measuredDimensions(kYGDefaultDimensionValues),
cachedLayout(YGCachedMeasurement()),
didUseLegacyFlag(false),
doesLegacyStretchFlagAffectsLayout(false) {}
bool YGLayout::operator==(YGLayout layout) const {
bool isEqual = YGFloatArrayEqual(position, layout.position) &&
YGFloatArrayEqual(dimensions, layout.dimensions) &&

View File

@@ -9,33 +9,36 @@
#include "YGFloatOptional.h"
#include "Yoga-internal.h"
struct YGLayout {
std::array<float, 4> position;
std::array<float, 2> dimensions;
std::array<float, 6> margin;
std::array<float, 6> border;
std::array<float, 6> padding;
YGDirection direction;
constexpr std::array<float, 2> kYGDefaultDimensionValues = {
{YGUndefined, YGUndefined}};
uint32_t computedFlexBasisGeneration;
YGFloatOptional computedFlexBasis;
bool hadOverflow;
struct YGLayout {
std::array<float, 4> position = {};
std::array<float, 2> dimensions = kYGDefaultDimensionValues;
std::array<float, 6> margin = {};
std::array<float, 6> border = {};
std::array<float, 6> padding = {};
YGDirection direction = YGDirectionInherit;
uint32_t computedFlexBasisGeneration = 0;
YGFloatOptional computedFlexBasis = {};
bool hadOverflow = false;
// Instead of recomputing the entire layout every single time, we
// cache some information to break early when nothing changed
uint32_t generationCount;
YGDirection lastOwnerDirection;
uint32_t generationCount = 0;
YGDirection lastOwnerDirection = (YGDirection)-1;
uint32_t nextCachedMeasurementsIndex;
uint32_t nextCachedMeasurementsIndex = 0;
std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>
cachedMeasurements;
std::array<float, 2> measuredDimensions;
cachedMeasurements = {};
std::array<float, 2> measuredDimensions = kYGDefaultDimensionValues;
YGCachedMeasurement cachedLayout;
bool didUseLegacyFlag;
bool doesLegacyStretchFlagAffectsLayout;
YGCachedMeasurement cachedLayout = YGCachedMeasurement();
bool didUseLegacyFlag = false;
bool doesLegacyStretchFlagAffectsLayout = false;
YGLayout();
YGLayout() = default;
bool operator==(YGLayout layout) const;
bool operator!=(YGLayout layout) const {

View File

@@ -7,51 +7,6 @@
*/
#include "YGStyle.h"
const YGValue kYGValueUndefined = {0, YGUnitUndefined};
const YGValue kYGValueAuto = {0, YGUnitAuto};
const std::array<YGValue, YGEdgeCount> kYGDefaultEdgeValuesUnit = {
{kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined}};
const std::array<YGValue, 2> kYGDefaultDimensionValuesAutoUnit = {
{kYGValueAuto, kYGValueAuto}};
const std::array<YGValue, 2> kYGDefaultDimensionValuesUnit = {
{kYGValueUndefined, kYGValueUndefined}};
YGStyle::YGStyle()
: direction(YGDirectionInherit),
flexDirection(YGFlexDirectionColumn),
justifyContent(YGJustifyFlexStart),
alignContent(YGAlignFlexStart),
alignItems(YGAlignStretch),
alignSelf(YGAlignAuto),
positionType(YGPositionTypeRelative),
flexWrap(YGWrapNoWrap),
overflow(YGOverflowVisible),
display(YGDisplayFlex),
flex(YGFloatOptional()),
flexGrow(YGFloatOptional()),
flexShrink(YGFloatOptional()),
flexBasis(kYGValueAuto),
margin(kYGDefaultEdgeValuesUnit),
position(kYGDefaultEdgeValuesUnit),
padding(kYGDefaultEdgeValuesUnit),
border(kYGDefaultEdgeValuesUnit),
dimensions(kYGDefaultDimensionValuesAutoUnit),
minDimensions(kYGDefaultDimensionValuesUnit),
maxDimensions(kYGDefaultDimensionValuesUnit),
aspectRatio(YGFloatOptional()) {}
// Yoga specific properties, not compatible with flexbox specification
bool YGStyle::operator==(const YGStyle& style) {
bool areNonFloatValuesEqual = direction == style.direction &&

View File

@@ -10,34 +10,52 @@
#include "Yoga-internal.h"
#include "Yoga.h"
constexpr YGValue kYGValueUndefined = {0, YGUnitUndefined};
constexpr YGValue kYGValueAuto = {0, YGUnitAuto};
constexpr std::array<YGValue, YGEdgeCount> kYGDefaultEdgeValuesUnit = {
{kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined,
kYGValueUndefined}};
constexpr std::array<YGValue, 2> kYGDefaultDimensionValuesUnit = {
{kYGValueUndefined, kYGValueUndefined}};
struct YGStyle {
using Dimensions = std::array<YGValue, 2>;
YGDirection direction;
YGFlexDirection flexDirection;
YGJustify justifyContent;
YGAlign alignContent;
YGAlign alignItems;
YGAlign alignSelf;
YGPositionType positionType;
YGWrap flexWrap;
YGOverflow overflow;
YGDisplay display;
YGFloatOptional flex;
YGFloatOptional flexGrow;
YGFloatOptional flexShrink;
YGValue flexBasis;
std::array<YGValue, YGEdgeCount> margin;
std::array<YGValue, YGEdgeCount> position;
std::array<YGValue, YGEdgeCount> padding;
std::array<YGValue, YGEdgeCount> border;
Dimensions dimensions;
Dimensions minDimensions;
Dimensions maxDimensions;
YGDirection direction = YGDirectionInherit;
YGFlexDirection flexDirection = YGFlexDirectionColumn;
YGJustify justifyContent = YGJustifyFlexStart;
YGAlign alignContent = YGAlignFlexStart;
YGAlign alignItems = YGAlignStretch;
YGAlign alignSelf = YGAlignAuto;
YGPositionType positionType = YGPositionTypeRelative;
YGWrap flexWrap = YGWrapNoWrap;
YGOverflow overflow = YGOverflowVisible;
YGDisplay display = YGDisplayFlex;
YGFloatOptional flex = {};
YGFloatOptional flexGrow = {};
YGFloatOptional flexShrink = {};
YGValue flexBasis = kYGValueAuto;
std::array<YGValue, YGEdgeCount> margin = kYGDefaultEdgeValuesUnit;
std::array<YGValue, YGEdgeCount> position = kYGDefaultEdgeValuesUnit;
std::array<YGValue, YGEdgeCount> padding = kYGDefaultEdgeValuesUnit;
std::array<YGValue, YGEdgeCount> border = kYGDefaultEdgeValuesUnit;
Dimensions dimensions = {{kYGValueAuto, kYGValueAuto}};
Dimensions minDimensions = kYGDefaultDimensionValuesUnit;
Dimensions maxDimensions = kYGDefaultDimensionValuesUnit;
// Yoga specific properties, not compatible with flexbox specification
YGFloatOptional aspectRatio;
YGFloatOptional aspectRatio = {};
YGStyle();
YGStyle() = default;
bool operator==(const YGStyle& style);
bool operator!=(YGStyle style) {