YGNode: Field for web defaults

Summary:
In order to remove the config pointer from nodes, we have to keep track of whether the node is using web defaults.
This information fits into one bit that we can place in padding (i.e. no extra memory needed).

This allows us to get rid of config usage withing `YGNode` with some exceptions:

- `iterChildrenAfterCloningIfNeeded` -- this function will simply receive the configuration, or the cloning callback.
- `setAndPropogateUseLegacyFlag` -- will be removed in D15316863
- in `YGNode::reset` -- will go away utomatically once we remove the config pointer

Reviewed By: SidharthGuglani

Differential Revision: D15391536

fbshipit-source-id: 0fa0d0805c6862bd741fe4a7d9b637ed534f56a4
This commit is contained in:
David Aurelio
2019-05-20 10:37:59 -07:00
committed by Facebook Github Bot
parent aa71dbb5bd
commit 1938792517
3 changed files with 36 additions and 18 deletions

View File

@@ -22,6 +22,7 @@ YGNode::YGNode(YGNode&& node) {
measureUsesContext_ = node.measureUsesContext_;
baselineUsesContext_ = node.baselineUsesContext_;
printUsesContext_ = node.printUsesContext_;
useWebDefaults_ = node.useWebDefaults_;
measure_ = node.measure_;
baseline_ = node.baseline_;
print_ = node.print_;
@@ -38,6 +39,13 @@ YGNode::YGNode(YGNode&& node) {
}
}
YGNode::YGNode(const YGNode& node, YGConfigRef config) : YGNode{node} {
config_ = config;
if (config->useWebDefaults) {
useWebDefaults();
}
}
void YGNode::print(void* printContext) {
if (print_.noContext != nullptr) {
if (printUsesContext_) {
@@ -349,7 +357,7 @@ YGValue YGNode::resolveFlexBasisPtr() const {
return flexBasis;
}
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
return config_->useWebDefaults ? YGValueAuto : YGValueZero;
return useWebDefaults_ ? YGValueAuto : YGValueZero;
}
return YGValueAuto;
}
@@ -425,11 +433,11 @@ float YGNode::resolveFlexShrink() const {
if (!style_.flexShrink().isUndefined()) {
return style_.flexShrink().unwrap();
}
if (!config_->useWebDefaults && !style_.flex().isUndefined() &&
if (!useWebDefaults_ && !style_.flex().isUndefined() &&
style_.flex().unwrap() < 0.0f) {
return -style_.flex().unwrap();
}
return config_->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink;
return useWebDefaults_ ? kWebDefaultFlexShrink : kDefaultFlexShrink;
}
bool YGNode::isNodeFlexible() {
@@ -581,11 +589,9 @@ void YGNode::reset() {
clearChildren();
auto config = getConfig();
*this = YGNode{};
if (config->useWebDefaults) {
style_.flexDirection() = YGFlexDirectionRow;
style_.alignContent() = YGAlignStretch;
auto webDefaults = useWebDefaults_;
*this = YGNode{getConfig()};
if (webDefaults) {
useWebDefaults();
}
setConfig(config);
}