Allow lazy resolution of edge dimension values (#1453)

Summary:
X-link: https://github.com/facebook/react-native/pull/41347

Pull Request resolved: https://github.com/facebook/yoga/pull/1453

This follows the previous patterns used for `Gutters` and `Dimension`, where we hide CompactValue array implementation from `yoga::Style` callers.

This allows a single read of a style to only need access to the resolved values of a single edge, vs all edges. This is cheap now because the interface is the representation, but gets expensive if `StyleValuePool` is the actual implementation.

This prevents us from needing to resolve nine dimensions, in order to read a single value like `marginLeft`. Doing this, in the new style, also lets us remove `IdxRef` from the API.

We unroll the structure dependent parts in the props parsing code, for something more verbose, but also a bit clearer.

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D50998164

fbshipit-source-id: 248396f9587e29d62cde05ae7512d8194f60c809
This commit is contained in:
Nick Gerleman
2023-11-14 09:12:35 -08:00
committed by Facebook GitHub Bot
parent bb892af3a4
commit f2c8acad2c
9 changed files with 124 additions and 416 deletions

View File

@@ -65,6 +65,12 @@ class YG_EXPORT Node : public ::YGNode {
style_.alignContent() = Align::Stretch;
}
template <auto Field>
CompactValue computeEdgeValueForColumn(YGEdge edge) const;
template <auto Field>
CompactValue computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const;
// DANGER DANGER DANGER!
// If the node assigned to has children, we'd either have to deallocate
// them (potentially incorrect) or ignore them (danger of leaks). Only ever
@@ -189,15 +195,6 @@ class YG_EXPORT Node : public ::YGNode {
return resolvedDimensions_[static_cast<size_t>(dimension)];
}
static CompactValue computeEdgeValueForColumn(
const Style::Edges& edges,
YGEdge edge);
static CompactValue computeEdgeValueForRow(
const Style::Edges& edges,
YGEdge rowEdge,
YGEdge edge);
// Methods related to positions, margin, padding and border
bool isFlexStartPositionDefined(FlexDirection axis) const;
bool isInlineStartPositionDefined(FlexDirection axis, Direction direction)