update:yoga-caching-algorithm
This commit is contained in:
@@ -57,63 +57,49 @@ bool canUseCachedMeasurement(
|
|||||||
const float marginColumn,
|
const float marginColumn,
|
||||||
const yoga::Config* const config) {
|
const yoga::Config* const config) {
|
||||||
if ((yoga::isDefined(lastComputedHeight) && lastComputedHeight < 0) ||
|
if ((yoga::isDefined(lastComputedHeight) && lastComputedHeight < 0) ||
|
||||||
((yoga::isDefined(lastComputedWidth)) && lastComputedWidth < 0)) {
|
(yoga::isDefined(lastComputedWidth) && lastComputedWidth < 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float pointScaleFactor = config->getPointScaleFactor();
|
const float pointScaleFactor = config->getPointScaleFactor();
|
||||||
|
|
||||||
bool useRoundedComparison = config != nullptr && pointScaleFactor != 0;
|
bool useRoundedComparison = config != nullptr && pointScaleFactor != 0;
|
||||||
const float effectiveWidth = useRoundedComparison
|
|
||||||
? roundValueToPixelGrid(availableWidth, pointScaleFactor, false, false)
|
auto roundIfNeeded = [&](float value) {
|
||||||
: availableWidth;
|
return useRoundedComparison
|
||||||
const float effectiveHeight = useRoundedComparison
|
? roundValueToPixelGrid(value, pointScaleFactor, false, false)
|
||||||
? roundValueToPixelGrid(availableHeight, pointScaleFactor, false, false)
|
: value;
|
||||||
: availableHeight;
|
};
|
||||||
const float effectiveLastWidth = useRoundedComparison
|
|
||||||
? roundValueToPixelGrid(
|
const float effectiveWidth = roundIfNeeded(availableWidth);
|
||||||
lastAvailableWidth, pointScaleFactor, false, false)
|
const float effectiveHeight = roundIfNeeded(availableHeight);
|
||||||
: lastAvailableWidth;
|
const float effectiveLastWidth = roundIfNeeded(lastAvailableWidth);
|
||||||
const float effectiveLastHeight = useRoundedComparison
|
const float effectiveLastHeight = roundIfNeeded(lastAvailableHeight);
|
||||||
? roundValueToPixelGrid(
|
|
||||||
lastAvailableHeight, pointScaleFactor, false, false)
|
|
||||||
: lastAvailableHeight;
|
|
||||||
|
|
||||||
const bool hasSameWidthSpec = lastWidthMode == widthMode &&
|
const bool hasSameWidthSpec = lastWidthMode == widthMode &&
|
||||||
yoga::inexactEquals(effectiveLastWidth, effectiveWidth);
|
yoga::inexactEquals(effectiveLastWidth, effectiveWidth);
|
||||||
const bool hasSameHeightSpec = lastHeightMode == heightMode &&
|
const bool hasSameHeightSpec = lastHeightMode == heightMode &&
|
||||||
yoga::inexactEquals(effectiveLastHeight, effectiveHeight);
|
yoga::inexactEquals(effectiveLastHeight, effectiveHeight);
|
||||||
|
|
||||||
|
const float adjustedWidth = availableWidth - marginRow;
|
||||||
|
const float adjustedHeight = availableHeight - marginColumn;
|
||||||
|
|
||||||
const bool widthIsCompatible =
|
const bool widthIsCompatible =
|
||||||
hasSameWidthSpec ||
|
hasSameWidthSpec ||
|
||||||
sizeIsExactAndMatchesOldMeasuredSize(
|
sizeIsExactAndMatchesOldMeasuredSize(
|
||||||
widthMode, availableWidth - marginRow, lastComputedWidth) ||
|
widthMode, adjustedWidth, lastComputedWidth) ||
|
||||||
oldSizeIsMaxContentAndStillFits(
|
oldSizeIsMaxContentAndStillFits(
|
||||||
widthMode,
|
widthMode, adjustedWidth, lastWidthMode, lastComputedWidth) ||
|
||||||
availableWidth - marginRow,
|
|
||||||
lastWidthMode,
|
|
||||||
lastComputedWidth) ||
|
|
||||||
newSizeIsStricterAndStillValid(
|
newSizeIsStricterAndStillValid(
|
||||||
widthMode,
|
widthMode, adjustedWidth, lastWidthMode, lastAvailableWidth, lastComputedWidth);
|
||||||
availableWidth - marginRow,
|
|
||||||
lastWidthMode,
|
|
||||||
lastAvailableWidth,
|
|
||||||
lastComputedWidth);
|
|
||||||
|
|
||||||
const bool heightIsCompatible = hasSameHeightSpec ||
|
const bool heightIsCompatible =
|
||||||
|
hasSameHeightSpec ||
|
||||||
sizeIsExactAndMatchesOldMeasuredSize(
|
sizeIsExactAndMatchesOldMeasuredSize(
|
||||||
heightMode,
|
heightMode, adjustedHeight, lastComputedHeight) ||
|
||||||
availableHeight - marginColumn,
|
oldSizeIsMaxContentAndStillFits(
|
||||||
lastComputedHeight) ||
|
heightMode, adjustedHeight, lastHeightMode, lastComputedHeight) ||
|
||||||
oldSizeIsMaxContentAndStillFits(heightMode,
|
newSizeIsStricterAndStillValid(
|
||||||
availableHeight - marginColumn,
|
heightMode, adjustedHeight, lastHeightMode, lastAvailableHeight, lastComputedHeight);
|
||||||
lastHeightMode,
|
|
||||||
lastComputedHeight) ||
|
|
||||||
newSizeIsStricterAndStillValid(heightMode,
|
|
||||||
availableHeight - marginColumn,
|
|
||||||
lastHeightMode,
|
|
||||||
lastAvailableHeight,
|
|
||||||
lastComputedHeight);
|
|
||||||
|
|
||||||
return widthIsCompatible && heightIsCompatible;
|
return widthIsCompatible && heightIsCompatible;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user