Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update:yoga-caching-algorithm #1681

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 26 additions & 40 deletions yoga/algorithm/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,65 +57,51 @@ bool canUseCachedMeasurement(
const float marginColumn,
const yoga::Config* const config) {
if ((yoga::isDefined(lastComputedHeight) && lastComputedHeight < 0) ||
((yoga::isDefined(lastComputedWidth)) && lastComputedWidth < 0)) {
(yoga::isDefined(lastComputedWidth) && lastComputedWidth < 0)) {
return false;
}

const float pointScaleFactor = config->getPointScaleFactor();

bool useRoundedComparison = config != nullptr && pointScaleFactor != 0;
const float effectiveWidth = useRoundedComparison
? roundValueToPixelGrid(availableWidth, pointScaleFactor, false, false)
: availableWidth;
const float effectiveHeight = useRoundedComparison
? roundValueToPixelGrid(availableHeight, pointScaleFactor, false, false)
: availableHeight;
const float effectiveLastWidth = useRoundedComparison
? roundValueToPixelGrid(
lastAvailableWidth, pointScaleFactor, false, false)
: lastAvailableWidth;
const float effectiveLastHeight = useRoundedComparison
? roundValueToPixelGrid(
lastAvailableHeight, pointScaleFactor, false, false)
: lastAvailableHeight;

auto roundIfNeeded = [&](float value) {
return useRoundedComparison
? roundValueToPixelGrid(value, pointScaleFactor, false, false)
: value;
};

const float effectiveWidth = roundIfNeeded(availableWidth);
const float effectiveHeight = roundIfNeeded(availableHeight);
const float effectiveLastWidth = roundIfNeeded(lastAvailableWidth);
const float effectiveLastHeight = roundIfNeeded(lastAvailableHeight);

const bool hasSameWidthSpec = lastWidthMode == widthMode &&
yoga::inexactEquals(effectiveLastWidth, effectiveWidth);
const bool hasSameHeightSpec = lastHeightMode == heightMode &&
yoga::inexactEquals(effectiveLastHeight, effectiveHeight);

const float adjustedWidth = availableWidth - marginRow;
const float adjustedHeight = availableHeight - marginColumn;

const bool widthIsCompatible =
hasSameWidthSpec ||
sizeIsExactAndMatchesOldMeasuredSize(
widthMode, availableWidth - marginRow, lastComputedWidth) ||
widthMode, adjustedWidth, lastComputedWidth) ||
oldSizeIsMaxContentAndStillFits(
widthMode,
availableWidth - marginRow,
lastWidthMode,
lastComputedWidth) ||
widthMode, adjustedWidth, lastWidthMode, lastComputedWidth) ||
newSizeIsStricterAndStillValid(
widthMode,
availableWidth - marginRow,
lastWidthMode,
lastAvailableWidth,
lastComputedWidth);
widthMode, adjustedWidth, lastWidthMode, lastAvailableWidth, lastComputedWidth);

const bool heightIsCompatible = hasSameHeightSpec ||
const bool heightIsCompatible =
hasSameHeightSpec ||
sizeIsExactAndMatchesOldMeasuredSize(
heightMode,
availableHeight - marginColumn,
lastComputedHeight) ||
oldSizeIsMaxContentAndStillFits(heightMode,
availableHeight - marginColumn,
lastHeightMode,
lastComputedHeight) ||
newSizeIsStricterAndStillValid(heightMode,
availableHeight - marginColumn,
lastHeightMode,
lastAvailableHeight,
lastComputedHeight);
heightMode, adjustedHeight, lastComputedHeight) ||
oldSizeIsMaxContentAndStillFits(
heightMode, adjustedHeight, lastHeightMode, lastComputedHeight) ||
newSizeIsStricterAndStillValid(
heightMode, adjustedHeight, lastHeightMode, lastAvailableHeight, lastComputedHeight);

return widthIsCompatible && heightIsCompatible;
}

} // namespace facebook::yoga
} // namespace facebook::yoga
Loading