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