diff --git a/yoga/config/Config.cpp b/yoga/config/Config.cpp index 721588ee0a..b717d974d1 100644 --- a/yoga/config/Config.cpp +++ b/yoga/config/Config.cpp @@ -25,19 +25,19 @@ Config::Config(YGLogger logger) : cloneNodeCallback_{nullptr} { } void Config::setUseWebDefaults(bool useWebDefaults) { - flags_.useWebDefaults = useWebDefaults; + useWebDefaults_ = useWebDefaults; } bool Config::useWebDefaults() const { - return flags_.useWebDefaults; + return useWebDefaults_; } void Config::setShouldPrintTree(bool printTree) { - flags_.printTree = printTree; + printTree_ = printTree; } bool Config::shouldPrintTree() const { - return flags_.printTree; + return printTree_; } void Config::setExperimentalFeatureEnabled( diff --git a/yoga/config/Config.h b/yoga/config/Config.h index 227aa598bf..1bdc0469cf 100644 --- a/yoga/config/Config.h +++ b/yoga/config/Config.h @@ -30,15 +30,6 @@ bool configUpdateInvalidatesLayout( const Config& oldConfig, const Config& newConfig); -#pragma pack(push) -#pragma pack(1) -// Packed structure of <32-bit options to miminize size per node. -struct ConfigFlags { - bool useWebDefaults : 1; - bool printTree : 1; -}; -#pragma pack(pop) - class YG_EXPORT Config : public ::YGConfig { public: Config(YGLogger logger); @@ -82,7 +73,9 @@ class YG_EXPORT Config : public ::YGConfig { YGCloneNodeFunc cloneNodeCallback_; YGLogger logger_; - ConfigFlags flags_{}; + bool useWebDefaults_ : 1 = false; + bool printTree_ : 1 = false; + ExperimentalFeatureSet experimentalFeatures_{}; Errata errata_ = Errata::None; float pointScaleFactor_ = 1.0f; diff --git a/yoga/node/LayoutResults.h b/yoga/node/LayoutResults.h index c533f60dc3..2c0f36c172 100644 --- a/yoga/node/LayoutResults.h +++ b/yoga/node/LayoutResults.h @@ -15,14 +15,6 @@ namespace facebook::yoga { -#pragma pack(push) -#pragma pack(1) -struct LayoutResultFlags { - uint32_t direction : 2; - bool hadOverflow : 1; -}; -#pragma pack(pop) - struct LayoutResults { // This value was chosen based on empirical data: // 98% of analyzed layouts require less than 8 entries. @@ -35,7 +27,8 @@ struct LayoutResults { std::array padding = {}; private: - LayoutResultFlags flags_{}; + uint32_t direction_ : 2 = static_cast(YGDirectionInherit) & 0x03; + bool hadOverflow_ : 1 = false; public: uint32_t computedFlexBasisGeneration = 0; @@ -53,18 +46,18 @@ struct LayoutResults { CachedMeasurement cachedLayout{}; YGDirection direction() const { - return static_cast(flags_.direction); + return static_cast(direction_); } void setDirection(YGDirection direction) { - flags_.direction = static_cast(direction) & 0x03; + direction_ = static_cast(direction) & 0x03; } bool hadOverflow() const { - return flags_.hadOverflow; + return hadOverflow_; } void setHadOverflow(bool hadOverflow) { - flags_.hadOverflow = hadOverflow; + hadOverflow_ = hadOverflow; } bool operator==(LayoutResults layout) const; diff --git a/yoga/node/Node.cpp b/yoga/node/Node.cpp index 6f18c5768b..2763df9022 100644 --- a/yoga/node/Node.cpp +++ b/yoga/node/Node.cpp @@ -23,15 +23,17 @@ Node::Node(const yoga::Config* config) : config_{config} { yoga::assertFatal( config != nullptr, "Attempting to construct Node with null config"); - flags_.hasNewLayout = true; if (config->useWebDefaults()) { useWebDefaults(); } } Node::Node(Node&& node) { + hasNewLayout_ = node.hasNewLayout_; + isReferenceBaseline_ = node.isReferenceBaseline_; + isDirty_ = node.isDirty_; + nodeType_ = node.nodeType_; context_ = node.context_; - flags_ = node.flags_; measureFunc_ = node.measureFunc_; baselineFunc_ = node.baselineFunc_; printFunc_ = node.printFunc_; @@ -271,10 +273,10 @@ void Node::setConfig(yoga::Config* config) { } void Node::setDirty(bool isDirty) { - if (isDirty == flags_.isDirty) { + if (isDirty == isDirty_) { return; } - flags_.isDirty = isDirty; + isDirty_ = isDirty; if (isDirty && dirtiedFunc_) { dirtiedFunc_(this); } @@ -473,7 +475,7 @@ void Node::cloneChildrenIfNeeded() { } void Node::markDirtyAndPropagate() { - if (!flags_.isDirty) { + if (!isDirty_) { setDirty(true); setLayoutComputedFlexBasis(FloatOptional()); if (owner_) { @@ -483,7 +485,7 @@ void Node::markDirtyAndPropagate() { } void Node::markDirtyAndPropagateDownwards() { - flags_.isDirty = true; + isDirty_ = true; for_each(children_.begin(), children_.end(), [](Node* childNode) { childNode->markDirtyAndPropagateDownwards(); }); diff --git a/yoga/node/Node.h b/yoga/node/Node.h index e6aff53482..8d2cd67672 100644 --- a/yoga/node/Node.h +++ b/yoga/node/Node.h @@ -26,20 +26,13 @@ struct YGNode {}; namespace facebook::yoga { -#pragma pack(push) -#pragma pack(1) -struct NodeFlags { - bool hasNewLayout : 1; - bool isReferenceBaseline : 1; - bool isDirty : 1; - NodeType nodeType : bitCount(); -}; -#pragma pack(pop) - class YG_EXPORT Node : public ::YGNode { private: + bool hasNewLayout_ : 1 = true; + bool isReferenceBaseline_ : 1 = false; + bool isDirty_ : 1 = false; + NodeType nodeType_ : bitCount() = NodeType::Default; void* context_ = nullptr; - NodeFlags flags_ = {}; YGMeasureFunc measureFunc_ = {nullptr}; YGBaselineFunc baselineFunc_ = {nullptr}; YGPrintFunc printFunc_ = {nullptr}; @@ -92,11 +85,11 @@ class YG_EXPORT Node : public ::YGNode { void print(); bool getHasNewLayout() const { - return flags_.hasNewLayout; + return hasNewLayout_; } NodeType getNodeType() const { - return flags_.nodeType; + return nodeType_; } bool hasMeasureFunc() const noexcept { @@ -142,7 +135,7 @@ class YG_EXPORT Node : public ::YGNode { } bool isReferenceBaseline() const { - return flags_.isReferenceBaseline; + return isReferenceBaseline_; } // returns the Node that owns this Node. An owner is used to identify @@ -175,7 +168,7 @@ class YG_EXPORT Node : public ::YGNode { } bool isDirty() const { - return flags_.isDirty; + return isDirty_; } std::array getResolvedDimensions() const { @@ -250,11 +243,11 @@ class YG_EXPORT Node : public ::YGNode { } void setHasNewLayout(bool hasNewLayout) { - flags_.hasNewLayout = hasNewLayout; + hasNewLayout_ = hasNewLayout; } void setNodeType(NodeType nodeType) { - flags_.nodeType = nodeType; + nodeType_ = nodeType; } void setMeasureFunc(YGMeasureFunc measureFunc); @@ -280,7 +273,7 @@ class YG_EXPORT Node : public ::YGNode { } void setIsReferenceBaseline(bool isReferenceBaseline) { - flags_.isReferenceBaseline = isReferenceBaseline; + isReferenceBaseline_ = isReferenceBaseline; } void setOwner(Node* owner) {