Distinguish cached inline_content_sizes() from uncached ones (#34595)

Several structs and enums had a `inline_content_sizes()` method, but it
wasn't clear which ones would try to cache the result, and which ones
would always compute it.

Therefore, this performs some clarifying renaming:
 - Cached ones stay as `inline_content_sizes()`
 - Uncached ones become `compute_inline_content_sizes()`

Also, to simplify calls to `LayoutBoxBase::inline_content_sizes()`,
`compute_inline_content_sizes()` is moved into a new trait.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2024-12-12 16:39:51 +01:00 committed by GitHub
parent 874e106924
commit f7e2ec3a0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 152 additions and 125 deletions

View file

@ -7,9 +7,10 @@ use serde::Serialize;
use servo_arc::Arc;
use style::properties::ComputedValues;
use crate::context::LayoutContext;
use crate::fragment_tree::BaseFragmentInfo;
use crate::geom::SizeConstraint;
use crate::sizing::InlineContentSizesResult;
use crate::sizing::{ComputeInlineContentSizes, InlineContentSizesResult};
use crate::ConstraintSpace;
/// A box tree node that handles containing information about style and the original DOM
@ -41,8 +42,9 @@ impl LayoutBoxBase {
/// the result from a cache when possible.
pub(crate) fn inline_content_sizes(
&self,
layout_context: &LayoutContext,
constraint_space: &ConstraintSpace,
inline_content_sizes_fn: impl FnOnce() -> InlineContentSizesResult,
layout_box: &impl ComputeInlineContentSizes,
) -> InlineContentSizesResult {
let mut cache = self.cached_inline_content_size.borrow_mut();
if let Some((previous_cb_block_size, result)) = *cache {
@ -54,7 +56,7 @@ impl LayoutBoxBase {
// TODO: Should we keep multiple caches for various block sizes?
}
let result = inline_content_sizes_fn();
let result = layout_box.compute_inline_content_sizes(layout_context, constraint_space);
*cache = Some((constraint_space.block_size, result));
result
}