77#pragma once
88#include < cstdint>
99#include < stdio.h>
10+ #include " Bitfield.h"
1011#include " CompactValue.h"
1112#include " YGConfig.h"
1213#include " YGLayout.h"
@@ -23,15 +24,20 @@ struct YGNode {
2324 using PrintWithContextFn = void (*)(YGNode*, void *);
2425
2526private:
27+ static constexpr size_t hasNewLayout_ = 0 ;
28+ static constexpr size_t isReferenceBaseline_ = 1 ;
29+ static constexpr size_t isDirty_ = 2 ;
30+ static constexpr size_t nodeType_ = 3 ;
31+ static constexpr size_t measureUsesContext_ = 4 ;
32+ static constexpr size_t baselineUsesContext_ = 5 ;
33+ static constexpr size_t printUsesContext_ = 6 ;
34+ static constexpr size_t useWebDefaults_ = 7 ;
35+
2636 void * context_ = nullptr ;
27- bool hasNewLayout_ : 1 ;
28- bool isReferenceBaseline_ : 1 ;
29- bool isDirty_ : 1 ;
30- YGNodeType nodeType_ : 1 ;
31- bool measureUsesContext_ : 1 ;
32- bool baselineUsesContext_ : 1 ;
33- bool printUsesContext_ : 1 ;
34- bool useWebDefaults_ : 1 ;
37+ using Flags = facebook::yoga::
38+ Bitfield<uint8_t , bool , bool , bool , YGNodeType, bool , bool , bool , bool >;
39+ Flags flags_ =
40+ {true , false , false , YGNodeTypeDefault, false , false , false , false };
3541 uint8_t reserved_ = 0 ;
3642 union {
3743 YGMeasureFunc noContext;
@@ -63,7 +69,7 @@ struct YGNode {
6369 void setBaselineFunc (decltype (baseline_));
6470
6571 void useWebDefaults () {
66- useWebDefaults_ = true ;
72+ flags_. at < useWebDefaults_>() = true ;
6773 style_.flexDirection () = YGFlexDirectionRow;
6874 style_.alignContent () = YGAlignStretch;
6975 }
@@ -79,17 +85,8 @@ struct YGNode {
7985
8086public:
8187 YGNode () : YGNode{YGConfigGetDefault ()} {}
82- explicit YGNode (const YGConfigRef config)
83- : hasNewLayout_{true },
84- isReferenceBaseline_{false },
85- isDirty_{false },
86- nodeType_{YGNodeTypeDefault},
87- measureUsesContext_{false },
88- baselineUsesContext_{false },
89- printUsesContext_{false },
90- useWebDefaults_{config->useWebDefaults },
91- config_{config} {
92- if (useWebDefaults_) {
88+ explicit YGNode (const YGConfigRef config) : config_{config} {
89+ if (config->useWebDefaults ) {
9390 useWebDefaults ();
9491 }
9592 };
@@ -116,9 +113,9 @@ struct YGNode {
116113
117114 void print (void *);
118115
119- bool getHasNewLayout () const { return hasNewLayout_; }
116+ bool getHasNewLayout () const { return flags_. at < hasNewLayout_>() ; }
120117
121- YGNodeType getNodeType () const { return nodeType_; }
118+ YGNodeType getNodeType () const { return flags_. at < nodeType_>() ; }
122119
123120 bool hasMeasureFunc () const noexcept { return measure_.noContext != nullptr ; }
124121
@@ -144,7 +141,7 @@ struct YGNode {
144141
145142 uint32_t getLineIndex () const { return lineIndex_; }
146143
147- bool isReferenceBaseline () { return isReferenceBaseline_; }
144+ bool isReferenceBaseline () { return flags_. at < isReferenceBaseline_>() ; }
148145
149146 // returns the YGNodeRef that owns this YGNode. An owner is used to identify
150147 // the YogaTree that a YGNode belongs to. This method will return the parent
@@ -177,7 +174,7 @@ struct YGNode {
177174
178175 YGConfigRef getConfig () const { return config_; }
179176
180- bool isDirty () const { return isDirty_; }
177+ bool isDirty () const { return flags_. at < isDirty_>() ; }
181178
182179 std::array<YGValue, 2 > getResolvedDimensions () const {
183180 return resolvedDimensions_;
@@ -225,17 +222,19 @@ struct YGNode {
225222
226223 void setPrintFunc (YGPrintFunc printFunc) {
227224 print_.noContext = printFunc;
228- printUsesContext_ = false ;
225+ flags_. at < printUsesContext_>() = false ;
229226 }
230227 void setPrintFunc (PrintWithContextFn printFunc) {
231228 print_.withContext = printFunc;
232- printUsesContext_ = true ;
229+ flags_. at < printUsesContext_>() = true ;
233230 }
234231 void setPrintFunc (std::nullptr_t ) { setPrintFunc (YGPrintFunc{nullptr }); }
235232
236- void setHasNewLayout (bool hasNewLayout) { hasNewLayout_ = hasNewLayout; }
233+ void setHasNewLayout (bool hasNewLayout) {
234+ flags_.at <hasNewLayout_>() = hasNewLayout;
235+ }
237236
238- void setNodeType (YGNodeType nodeType) { nodeType_ = nodeType; }
237+ void setNodeType (YGNodeType nodeType) { flags_. at < nodeType_>() = nodeType; }
239238
240239 void setMeasureFunc (YGMeasureFunc measureFunc);
241240 void setMeasureFunc (MeasureWithContextFn);
@@ -244,11 +243,11 @@ struct YGNode {
244243 }
245244
246245 void setBaselineFunc (YGBaselineFunc baseLineFunc) {
247- baselineUsesContext_ = false ;
246+ flags_. at < baselineUsesContext_>() = false ;
248247 baseline_.noContext = baseLineFunc;
249248 }
250249 void setBaselineFunc (BaselineWithContextFn baseLineFunc) {
251- baselineUsesContext_ = true ;
250+ flags_. at < baselineUsesContext_>() = true ;
252251 baseline_.withContext = baseLineFunc;
253252 }
254253 void setBaselineFunc (std::nullptr_t ) {
@@ -264,7 +263,7 @@ struct YGNode {
264263 void setLineIndex (uint32_t lineIndex) { lineIndex_ = lineIndex; }
265264
266265 void setIsReferenceBaseline (bool isReferenceBaseline) {
267- isReferenceBaseline_ = isReferenceBaseline;
266+ flags_. at < isReferenceBaseline_>() = isReferenceBaseline;
268267 }
269268
270269 void setOwner (YGNodeRef owner) { owner_ = owner; }
0 commit comments