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:
committed by
Facebook Github Bot
parent
aa71dbb5bd
commit
1938792517
@@ -13,6 +13,8 @@
|
||||
#include "YGStyle.h"
|
||||
#include "Yoga-internal.h"
|
||||
|
||||
YGConfigRef YGConfigGetDefault();
|
||||
|
||||
struct YGNode {
|
||||
using MeasureWithContextFn =
|
||||
YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*);
|
||||
@@ -28,6 +30,7 @@ private:
|
||||
bool measureUsesContext_ : 1;
|
||||
bool baselineUsesContext_ : 1;
|
||||
bool printUsesContext_ : 1;
|
||||
bool useWebDefaults_ : 1;
|
||||
uint8_t reserved_ = 0;
|
||||
union {
|
||||
YGMeasureFunc noContext;
|
||||
@@ -58,6 +61,12 @@ private:
|
||||
void setMeasureFunc(decltype(measure_));
|
||||
void setBaselineFunc(decltype(baseline_));
|
||||
|
||||
void useWebDefaults() {
|
||||
useWebDefaults_ = true;
|
||||
style_.flexDirection() = YGFlexDirectionRow;
|
||||
style_.alignContent() = YGAlignStretch;
|
||||
}
|
||||
|
||||
// DANGER DANGER DANGER!
|
||||
// If the the node assigned to has children, we'd either have to deallocate
|
||||
// them (potentially incorrect) or ignore them (danger of leaks). Only ever
|
||||
@@ -68,8 +77,8 @@ private:
|
||||
using CompactValue = facebook::yoga::detail::CompactValue;
|
||||
|
||||
public:
|
||||
YGNode() : YGNode{nullptr} {}
|
||||
explicit YGNode(const YGConfigRef newConfig)
|
||||
YGNode() : YGNode{YGConfigGetDefault()} {}
|
||||
explicit YGNode(const YGConfigRef config)
|
||||
: hasNewLayout_{true},
|
||||
isReferenceBaseline_{false},
|
||||
isDirty_{false},
|
||||
@@ -77,7 +86,12 @@ public:
|
||||
measureUsesContext_{false},
|
||||
baselineUsesContext_{false},
|
||||
printUsesContext_{false},
|
||||
config_{newConfig} {};
|
||||
useWebDefaults_{config->useWebDefaults},
|
||||
config_{config} {
|
||||
if (useWebDefaults_) {
|
||||
useWebDefaults();
|
||||
}
|
||||
};
|
||||
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
|
||||
|
||||
YGNode(YGNode&&);
|
||||
@@ -86,6 +100,9 @@ public:
|
||||
// Should we remove this?
|
||||
YGNode(const YGNode& node) = default;
|
||||
|
||||
// for RB fabric
|
||||
YGNode(const YGNode& node, YGConfigRef config);
|
||||
|
||||
// assignment means potential leaks of existing children, or alternatively
|
||||
// freeing unowned memory, double free, or freeing stack memory.
|
||||
YGNode& operator=(const YGNode&) = delete;
|
||||
|
Reference in New Issue
Block a user