Remove bitfield from YGNode.h
Summary: ##Changelog: [Internal][Yoga] remove Bitfield from YGNode.h Reviewed By: astreet Differential Revision: D18519633 fbshipit-source-id: b5a7d8d5ee960c5618df382900c4ded3da0587a6
This commit is contained in:
committed by
Facebook Github Bot
parent
aeb9549af7
commit
f7f134274c
@@ -16,7 +16,7 @@ using facebook::yoga::detail::CompactValue;
|
|||||||
|
|
||||||
YGNode::YGNode(YGNode&& node) {
|
YGNode::YGNode(YGNode&& node) {
|
||||||
context_ = node.context_;
|
context_ = node.context_;
|
||||||
flags_ = node.flags_;
|
flags = node.flags;
|
||||||
measure_ = node.measure_;
|
measure_ = node.measure_;
|
||||||
baseline_ = node.baseline_;
|
baseline_ = node.baseline_;
|
||||||
print_ = node.print_;
|
print_ = node.print_;
|
||||||
@@ -42,7 +42,7 @@ YGNode::YGNode(const YGNode& node, YGConfigRef config) : YGNode{node} {
|
|||||||
|
|
||||||
void YGNode::print(void* printContext) {
|
void YGNode::print(void* printContext) {
|
||||||
if (print_.noContext != nullptr) {
|
if (print_.noContext != nullptr) {
|
||||||
if (flags_.at<printUsesContext_>()) {
|
if (facebook::yoga::detail::getBooleanData(flags, printUsesContext_)) {
|
||||||
print_.withContext(this, printContext);
|
print_.withContext(this, printContext);
|
||||||
} else {
|
} else {
|
||||||
print_.noContext(this);
|
print_.noContext(this);
|
||||||
@@ -148,14 +148,14 @@ YGSize YGNode::measure(
|
|||||||
YGMeasureMode heightMode,
|
YGMeasureMode heightMode,
|
||||||
void* layoutContext) {
|
void* layoutContext) {
|
||||||
|
|
||||||
return flags_.at<measureUsesContext_>()
|
return facebook::yoga::detail::getBooleanData(flags, measureUsesContext_)
|
||||||
? measure_.withContext(
|
? measure_.withContext(
|
||||||
this, width, widthMode, height, heightMode, layoutContext)
|
this, width, widthMode, height, heightMode, layoutContext)
|
||||||
: measure_.noContext(this, width, widthMode, height, heightMode);
|
: measure_.noContext(this, width, widthMode, height, heightMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
float YGNode::baseline(float width, float height, void* layoutContext) {
|
float YGNode::baseline(float width, float height, void* layoutContext) {
|
||||||
return flags_.at<baselineUsesContext_>()
|
return facebook::yoga::detail::getBooleanData(flags, baselineUsesContext_)
|
||||||
? baseline_.withContext(this, width, height, layoutContext)
|
? baseline_.withContext(this, width, height, layoutContext)
|
||||||
: baseline_.noContext(this, width, height);
|
: baseline_.noContext(this, width, height);
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ void YGNode::setMeasureFunc(decltype(YGNode::measure_) measureFunc) {
|
|||||||
if (measureFunc.noContext == nullptr) {
|
if (measureFunc.noContext == nullptr) {
|
||||||
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
|
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
|
||||||
// places in Litho
|
// places in Litho
|
||||||
flags_.at<nodeType_>() = YGNodeTypeDefault;
|
setNodeType(YGNodeTypeDefault);
|
||||||
} else {
|
} else {
|
||||||
YGAssertWithNode(
|
YGAssertWithNode(
|
||||||
this,
|
this,
|
||||||
@@ -182,14 +182,14 @@ void YGNode::setMeasureFunc(decltype(YGNode::measure_) measureFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
|
void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
|
||||||
flags_.at<measureUsesContext_>() = false;
|
facebook::yoga::detail::setBooleanData(flags, measureUsesContext_, false);
|
||||||
decltype(YGNode::measure_) m;
|
decltype(YGNode::measure_) m;
|
||||||
m.noContext = measureFunc;
|
m.noContext = measureFunc;
|
||||||
setMeasureFunc(m);
|
setMeasureFunc(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNode::setMeasureFunc(MeasureWithContextFn measureFunc) {
|
YOGA_EXPORT void YGNode::setMeasureFunc(MeasureWithContextFn measureFunc) {
|
||||||
flags_.at<measureUsesContext_>() = true;
|
facebook::yoga::detail::setBooleanData(flags, measureUsesContext_, true);
|
||||||
decltype(YGNode::measure_) m;
|
decltype(YGNode::measure_) m;
|
||||||
m.withContext = measureFunc;
|
m.withContext = measureFunc;
|
||||||
setMeasureFunc(m);
|
setMeasureFunc(m);
|
||||||
@@ -208,10 +208,10 @@ void YGNode::insertChild(YGNodeRef child, uint32_t index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNode::setDirty(bool isDirty) {
|
void YGNode::setDirty(bool isDirty) {
|
||||||
if (isDirty == flags_.at<isDirty_>()) {
|
if (isDirty == facebook::yoga::detail::getBooleanData(flags, isDirty_)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
flags_.at<isDirty_>() = isDirty;
|
facebook::yoga::detail::setBooleanData(flags, isDirty_, isDirty);
|
||||||
if (isDirty && dirtied_) {
|
if (isDirty && dirtied_) {
|
||||||
dirtied_(this);
|
dirtied_(this);
|
||||||
}
|
}
|
||||||
@@ -351,7 +351,9 @@ YGValue YGNode::resolveFlexBasisPtr() const {
|
|||||||
return flexBasis;
|
return flexBasis;
|
||||||
}
|
}
|
||||||
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
|
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
|
||||||
return flags_.at<useWebDefaults_>() ? YGValueAuto : YGValueZero;
|
return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_)
|
||||||
|
? YGValueAuto
|
||||||
|
: YGValueZero;
|
||||||
}
|
}
|
||||||
return YGValueAuto;
|
return YGValueAuto;
|
||||||
}
|
}
|
||||||
@@ -390,7 +392,7 @@ void YGNode::cloneChildrenIfNeeded(void* cloneContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNode::markDirtyAndPropogate() {
|
void YGNode::markDirtyAndPropogate() {
|
||||||
if (!flags_.at<isDirty_>()) {
|
if (!facebook::yoga::detail::getBooleanData(flags, isDirty_)) {
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
setLayoutComputedFlexBasis(YGFloatOptional());
|
setLayoutComputedFlexBasis(YGFloatOptional());
|
||||||
if (owner_) {
|
if (owner_) {
|
||||||
@@ -400,7 +402,7 @@ void YGNode::markDirtyAndPropogate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNode::markDirtyAndPropogateDownwards() {
|
void YGNode::markDirtyAndPropogateDownwards() {
|
||||||
flags_.at<isDirty_>() = true;
|
facebook::yoga::detail::setBooleanData(flags, isDirty_, true);
|
||||||
for_each(children_.begin(), children_.end(), [](YGNodeRef childNode) {
|
for_each(children_.begin(), children_.end(), [](YGNodeRef childNode) {
|
||||||
childNode->markDirtyAndPropogateDownwards();
|
childNode->markDirtyAndPropogateDownwards();
|
||||||
});
|
});
|
||||||
@@ -427,12 +429,13 @@ float YGNode::resolveFlexShrink() const {
|
|||||||
if (!style_.flexShrink().isUndefined()) {
|
if (!style_.flexShrink().isUndefined()) {
|
||||||
return style_.flexShrink().unwrap();
|
return style_.flexShrink().unwrap();
|
||||||
}
|
}
|
||||||
if (!flags_.at<useWebDefaults_>() && !style_.flex().isUndefined() &&
|
if (!facebook::yoga::detail::getBooleanData(flags, useWebDefaults_) &&
|
||||||
style_.flex().unwrap() < 0.0f) {
|
!style_.flex().isUndefined() && style_.flex().unwrap() < 0.0f) {
|
||||||
return -style_.flex().unwrap();
|
return -style_.flex().unwrap();
|
||||||
}
|
}
|
||||||
return flags_.at<useWebDefaults_>() ? kWebDefaultFlexShrink
|
return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_)
|
||||||
: kDefaultFlexShrink;
|
? kWebDefaultFlexShrink
|
||||||
|
: kDefaultFlexShrink;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGNode::isNodeFlexible() {
|
bool YGNode::isNodeFlexible() {
|
||||||
@@ -577,7 +580,8 @@ void YGNode::reset() {
|
|||||||
|
|
||||||
clearChildren();
|
clearChildren();
|
||||||
|
|
||||||
auto webDefaults = flags_.at<useWebDefaults_>();
|
auto webDefaults =
|
||||||
|
facebook::yoga::detail::getBooleanData(flags, useWebDefaults_);
|
||||||
*this = YGNode{getConfig()};
|
*this = YGNode{getConfig()};
|
||||||
if (webDefaults) {
|
if (webDefaults) {
|
||||||
useWebDefaults();
|
useWebDefaults();
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "Bitfield.h"
|
#include "BitUtils.h"
|
||||||
#include "CompactValue.h"
|
#include "CompactValue.h"
|
||||||
#include "YGConfig.h"
|
#include "YGConfig.h"
|
||||||
#include "YGLayout.h"
|
#include "YGLayout.h"
|
||||||
@@ -35,10 +35,7 @@ private:
|
|||||||
static constexpr size_t useWebDefaults_ = 7;
|
static constexpr size_t useWebDefaults_ = 7;
|
||||||
|
|
||||||
void* context_ = nullptr;
|
void* context_ = nullptr;
|
||||||
using Flags = facebook::yoga::
|
uint8_t flags = 1;
|
||||||
Bitfield<uint8_t, bool, bool, bool, YGNodeType, bool, bool, bool, bool>;
|
|
||||||
Flags flags_ =
|
|
||||||
{true, false, false, YGNodeTypeDefault, false, false, false, false};
|
|
||||||
uint8_t reserved_ = 0;
|
uint8_t reserved_ = 0;
|
||||||
union {
|
union {
|
||||||
YGMeasureFunc noContext;
|
YGMeasureFunc noContext;
|
||||||
@@ -70,7 +67,7 @@ private:
|
|||||||
void setBaselineFunc(decltype(baseline_));
|
void setBaselineFunc(decltype(baseline_));
|
||||||
|
|
||||||
void useWebDefaults() {
|
void useWebDefaults() {
|
||||||
flags_.at<useWebDefaults_>() = true;
|
facebook::yoga::detail::setBooleanData(flags, useWebDefaults_, true);
|
||||||
style_.flexDirection() = YGFlexDirectionRow;
|
style_.flexDirection() = YGFlexDirectionRow;
|
||||||
style_.alignContent() = YGAlignStretch;
|
style_.alignContent() = YGAlignStretch;
|
||||||
}
|
}
|
||||||
@@ -114,9 +111,13 @@ public:
|
|||||||
|
|
||||||
void print(void*);
|
void print(void*);
|
||||||
|
|
||||||
bool getHasNewLayout() const { return flags_.at<hasNewLayout_>(); }
|
bool getHasNewLayout() const {
|
||||||
|
return facebook::yoga::detail::getBooleanData(flags, hasNewLayout_);
|
||||||
|
}
|
||||||
|
|
||||||
YGNodeType getNodeType() const { return flags_.at<nodeType_>(); }
|
YGNodeType getNodeType() const {
|
||||||
|
return facebook::yoga::detail::getEnumData<YGNodeType>(flags, nodeType_);
|
||||||
|
}
|
||||||
|
|
||||||
bool hasMeasureFunc() const noexcept { return measure_.noContext != nullptr; }
|
bool hasMeasureFunc() const noexcept { return measure_.noContext != nullptr; }
|
||||||
|
|
||||||
@@ -142,7 +143,9 @@ public:
|
|||||||
|
|
||||||
uint32_t getLineIndex() const { return lineIndex_; }
|
uint32_t getLineIndex() const { return lineIndex_; }
|
||||||
|
|
||||||
bool isReferenceBaseline() { return flags_.at<isReferenceBaseline_>(); }
|
bool isReferenceBaseline() {
|
||||||
|
return facebook::yoga::detail::getBooleanData(flags, isReferenceBaseline_);
|
||||||
|
}
|
||||||
|
|
||||||
// returns the YGNodeRef that owns this YGNode. An owner is used to identify
|
// returns the YGNodeRef that owns this YGNode. An owner is used to identify
|
||||||
// the YogaTree that a YGNode belongs to. This method will return the parent
|
// the YogaTree that a YGNode belongs to. This method will return the parent
|
||||||
@@ -175,7 +178,9 @@ public:
|
|||||||
|
|
||||||
YGConfigRef getConfig() const { return config_; }
|
YGConfigRef getConfig() const { return config_; }
|
||||||
|
|
||||||
bool isDirty() const { return flags_.at<isDirty_>(); }
|
bool isDirty() const {
|
||||||
|
return facebook::yoga::detail::getBooleanData(flags, isDirty_);
|
||||||
|
}
|
||||||
|
|
||||||
std::array<YGValue, 2> getResolvedDimensions() const {
|
std::array<YGValue, 2> getResolvedDimensions() const {
|
||||||
return resolvedDimensions_;
|
return resolvedDimensions_;
|
||||||
@@ -223,19 +228,22 @@ public:
|
|||||||
|
|
||||||
void setPrintFunc(YGPrintFunc printFunc) {
|
void setPrintFunc(YGPrintFunc printFunc) {
|
||||||
print_.noContext = printFunc;
|
print_.noContext = printFunc;
|
||||||
flags_.at<printUsesContext_>() = false;
|
facebook::yoga::detail::setBooleanData(flags, printUsesContext_, false);
|
||||||
}
|
}
|
||||||
void setPrintFunc(PrintWithContextFn printFunc) {
|
void setPrintFunc(PrintWithContextFn printFunc) {
|
||||||
print_.withContext = printFunc;
|
print_.withContext = printFunc;
|
||||||
flags_.at<printUsesContext_>() = true;
|
facebook::yoga::detail::setBooleanData(flags, printUsesContext_, true);
|
||||||
}
|
}
|
||||||
void setPrintFunc(std::nullptr_t) { setPrintFunc(YGPrintFunc{nullptr}); }
|
void setPrintFunc(std::nullptr_t) { setPrintFunc(YGPrintFunc{nullptr}); }
|
||||||
|
|
||||||
void setHasNewLayout(bool hasNewLayout) {
|
void setHasNewLayout(bool hasNewLayout) {
|
||||||
flags_.at<hasNewLayout_>() = hasNewLayout;
|
facebook::yoga::detail::setBooleanData(flags, hasNewLayout_, hasNewLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNodeType(YGNodeType nodeType) { flags_.at<nodeType_>() = nodeType; }
|
void setNodeType(YGNodeType nodeType) {
|
||||||
|
return facebook::yoga::detail::setEnumData<YGNodeType>(
|
||||||
|
flags, nodeType_, nodeType);
|
||||||
|
}
|
||||||
|
|
||||||
void setMeasureFunc(YGMeasureFunc measureFunc);
|
void setMeasureFunc(YGMeasureFunc measureFunc);
|
||||||
void setMeasureFunc(MeasureWithContextFn);
|
void setMeasureFunc(MeasureWithContextFn);
|
||||||
@@ -244,11 +252,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setBaselineFunc(YGBaselineFunc baseLineFunc) {
|
void setBaselineFunc(YGBaselineFunc baseLineFunc) {
|
||||||
flags_.at<baselineUsesContext_>() = false;
|
facebook::yoga::detail::setBooleanData(flags, baselineUsesContext_, false);
|
||||||
baseline_.noContext = baseLineFunc;
|
baseline_.noContext = baseLineFunc;
|
||||||
}
|
}
|
||||||
void setBaselineFunc(BaselineWithContextFn baseLineFunc) {
|
void setBaselineFunc(BaselineWithContextFn baseLineFunc) {
|
||||||
flags_.at<baselineUsesContext_>() = true;
|
facebook::yoga::detail::setBooleanData(flags, baselineUsesContext_, true);
|
||||||
baseline_.withContext = baseLineFunc;
|
baseline_.withContext = baseLineFunc;
|
||||||
}
|
}
|
||||||
void setBaselineFunc(std::nullptr_t) {
|
void setBaselineFunc(std::nullptr_t) {
|
||||||
@@ -264,7 +272,8 @@ public:
|
|||||||
void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; }
|
void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; }
|
||||||
|
|
||||||
void setIsReferenceBaseline(bool isReferenceBaseline) {
|
void setIsReferenceBaseline(bool isReferenceBaseline) {
|
||||||
flags_.at<isReferenceBaseline_>() = isReferenceBaseline;
|
facebook::yoga::detail::setBooleanData(
|
||||||
|
flags, isReferenceBaseline_, isReferenceBaseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setOwner(YGNodeRef owner) { owner_ = owner; }
|
void setOwner(YGNodeRef owner) { owner_ = owner; }
|
||||||
|
Reference in New Issue
Block a user