Revert D4957570: [yoga] Consolidate measure cache for layout nodes and leaf nodes
Summary: This reverts commit 5c5f39b67bd3f72d92b939ecee2d9a46c80b583f Differential Revision: D4957570 fbshipit-source-id: 4d30de37c6911aac2dc1243a54914515aabfb229
This commit is contained in:
committed by
Facebook Github Bot
parent
0ee3303791
commit
e3dbef7cbd
40
yoga/Yoga.c
40
yoga/Yoga.c
@@ -3116,18 +3116,26 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
layout->cachedLayout.computedHeight = -1;
|
layout->cachedLayout.computedHeight = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
YGCachedMeasurement *cachedResults = NULL;
|
||||||
|
|
||||||
// Determine whether the results are already cached. We maintain a separate
|
// Determine whether the results are already cached. We maintain a separate
|
||||||
// cache for layouts and measurements. A layout operation modifies the
|
// cache for layouts and measurements. A layout operation modifies the
|
||||||
// positions and dimensions for nodes in the subtree. The algorithm assumes that each
|
// positions
|
||||||
// node gets layed out a maximum of one time per tree layout, but multiple
|
// and dimensions for nodes in the subtree. The algorithm assumes that each
|
||||||
// measurements may be required to resolve all of the flex dimensions.
|
// node
|
||||||
|
// gets layed out a maximum of one time per tree layout, but multiple
|
||||||
YGCachedMeasurement *cachedResults = NULL;
|
// measurements
|
||||||
|
// may be required to resolve all of the flex dimensions.
|
||||||
|
// We handle nodes with measure functions specially here because they are the
|
||||||
|
// most
|
||||||
|
// expensive to measure, so it's worth avoiding redundant measurements if at
|
||||||
|
// all possible.
|
||||||
|
if (node->measure) {
|
||||||
const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth);
|
const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth);
|
||||||
const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
||||||
|
|
||||||
// First, try to use the layout cache.
|
// First, try to use the layout cache.
|
||||||
if ((node->measure || performLayout) && YGNodeCanUseCachedMeasurement(widthMeasureMode,
|
if (YGNodeCanUseCachedMeasurement(widthMeasureMode,
|
||||||
availableWidth,
|
availableWidth,
|
||||||
heightMeasureMode,
|
heightMeasureMode,
|
||||||
availableHeight,
|
availableHeight,
|
||||||
@@ -3140,7 +3148,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
marginAxisRow,
|
marginAxisRow,
|
||||||
marginAxisColumn)) {
|
marginAxisColumn)) {
|
||||||
cachedResults = &layout->cachedLayout;
|
cachedResults = &layout->cachedLayout;
|
||||||
} else if (node->measure || !performLayout) {
|
} else {
|
||||||
// Try to use the measurement cache.
|
// Try to use the measurement cache.
|
||||||
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
|
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
|
||||||
if (YGNodeCanUseCachedMeasurement(widthMeasureMode,
|
if (YGNodeCanUseCachedMeasurement(widthMeasureMode,
|
||||||
@@ -3160,6 +3168,24 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (performLayout) {
|
||||||
|
if (YGFloatsEqual(layout->cachedLayout.availableWidth, availableWidth) &&
|
||||||
|
YGFloatsEqual(layout->cachedLayout.availableHeight, availableHeight) &&
|
||||||
|
layout->cachedLayout.widthMeasureMode == widthMeasureMode &&
|
||||||
|
layout->cachedLayout.heightMeasureMode == heightMeasureMode) {
|
||||||
|
cachedResults = &layout->cachedLayout;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
|
||||||
|
if (YGFloatsEqual(layout->cachedMeasurements[i].availableWidth, availableWidth) &&
|
||||||
|
YGFloatsEqual(layout->cachedMeasurements[i].availableHeight, availableHeight) &&
|
||||||
|
layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode &&
|
||||||
|
layout->cachedMeasurements[i].heightMeasureMode == heightMeasureMode) {
|
||||||
|
cachedResults = &layout->cachedMeasurements[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!needToVisitNode && cachedResults != NULL) {
|
if (!needToVisitNode && cachedResults != NULL) {
|
||||||
layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth;
|
layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth;
|
||||||
|
Reference in New Issue
Block a user