layout: Refine the check for dependending on available space (#34907)

When laying out a block-level box that avoids floats, if we know that
its size doesn't depend on the available space, we can take a fast path
and only lay it out once. If its size depends on the available space,
we may have to lay it out multiple times, which can be slower.

This patch improves the check for this dependency on the available space.
For example, `min-width: 200px; width: 100px; max-width: stretch` was
previously considered to depend on the available space because of
`max-width`. However, `max-width` is irrelevant when the min size is
greater than the preferred size.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-01-08 10:22:01 -08:00 committed by GitHub
parent 51a1aeb535
commit 02c10fc502
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 16 deletions

View file

@ -899,18 +899,6 @@ impl Sizes {
}
}
#[inline]
pub(crate) fn depends_on_available_space(&self) -> bool {
// TODO: this logic could be refined further, since even if some of the 3 sizes
// depends on the available space, the resulting size might not. For example,
// `min-width: 200px; width: 100px; max-width: stretch`.
matches!(
self.preferred,
Size::Initial | Size::Stretch | Size::FitContent
) || matches!(self.min, Size::Stretch | Size::FitContent) ||
matches!(self.max, Size::Stretch | Size::FitContent)
}
/// Resolves the three sizes into a single numerical value.
#[inline]
pub(crate) fn resolve(