diff --git a/yoga/YGConfig.cpp b/yoga/YGConfig.cpp index 646f8d92..e0edd3f7 100644 --- a/yoga/YGConfig.cpp +++ b/yoga/YGConfig.cpp @@ -7,16 +7,4 @@ */ #include "YGConfig.h" -const std::array - 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) {} diff --git a/yoga/YGConfig.h b/yoga/YGConfig.h index 3718133a..941e0dcd 100644 --- a/yoga/YGConfig.h +++ b/yoga/YGConfig.h @@ -10,15 +10,15 @@ #include "Yoga.h" struct YGConfig { - std::array experimentalFeatures; - bool useWebDefaults; - bool useLegacyStretchBehaviour; - bool shouldDiffLayoutWithoutLegacyStretchBehaviour; - float pointScaleFactor; + std::array 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); }; diff --git a/yoga/YGFloatOptional.h b/yoga/YGFloatOptional.h index 00acc313..2578b9dd 100644 --- a/yoga/YGFloatOptional.h +++ b/yoga/YGFloatOptional.h @@ -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. diff --git a/yoga/YGLayout.cpp b/yoga/YGLayout.cpp index fea7015f..0f362f88 100644 --- a/yoga/YGLayout.cpp +++ b/yoga/YGLayout.cpp @@ -10,28 +10,6 @@ using namespace facebook; -const std::array 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) && diff --git a/yoga/YGLayout.h b/yoga/YGLayout.h index 22f2a1eb..812ed6bd 100644 --- a/yoga/YGLayout.h +++ b/yoga/YGLayout.h @@ -9,33 +9,36 @@ #include "YGFloatOptional.h" #include "Yoga-internal.h" -struct YGLayout { - std::array position; - std::array dimensions; - std::array margin; - std::array border; - std::array padding; - YGDirection direction; +constexpr std::array kYGDefaultDimensionValues = { + {YGUndefined, YGUndefined}}; - uint32_t computedFlexBasisGeneration; - YGFloatOptional computedFlexBasis; - bool hadOverflow; +struct YGLayout { + std::array position = {}; + std::array dimensions = kYGDefaultDimensionValues; + std::array margin = {}; + std::array border = {}; + std::array 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 - cachedMeasurements; - std::array measuredDimensions; + cachedMeasurements = {}; + std::array 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 { diff --git a/yoga/YGStyle.cpp b/yoga/YGStyle.cpp index 44fd9e50..46a65b28 100644 --- a/yoga/YGStyle.cpp +++ b/yoga/YGStyle.cpp @@ -7,51 +7,6 @@ */ #include "YGStyle.h" -const YGValue kYGValueUndefined = {0, YGUnitUndefined}; - -const YGValue kYGValueAuto = {0, YGUnitAuto}; - -const std::array kYGDefaultEdgeValuesUnit = { - {kYGValueUndefined, - kYGValueUndefined, - kYGValueUndefined, - kYGValueUndefined, - kYGValueUndefined, - kYGValueUndefined, - kYGValueUndefined, - kYGValueUndefined, - kYGValueUndefined}}; - -const std::array kYGDefaultDimensionValuesAutoUnit = { - {kYGValueAuto, kYGValueAuto}}; - -const std::array 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 && diff --git a/yoga/YGStyle.h b/yoga/YGStyle.h index efd52fff..04a74545 100644 --- a/yoga/YGStyle.h +++ b/yoga/YGStyle.h @@ -10,34 +10,52 @@ #include "Yoga-internal.h" #include "Yoga.h" +constexpr YGValue kYGValueUndefined = {0, YGUnitUndefined}; + +constexpr YGValue kYGValueAuto = {0, YGUnitAuto}; + +constexpr std::array kYGDefaultEdgeValuesUnit = { + {kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined, + kYGValueUndefined}}; + +constexpr std::array kYGDefaultDimensionValuesUnit = { + {kYGValueUndefined, kYGValueUndefined}}; + struct YGStyle { using Dimensions = std::array; - 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 margin; - std::array position; - std::array padding; - std::array 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 margin = kYGDefaultEdgeValuesUnit; + std::array position = kYGDefaultEdgeValuesUnit; + std::array padding = kYGDefaultEdgeValuesUnit; + std::array 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) {