Use a RwLock to cache inline_content_sizes() (#34232)

In order to support size keywords in block layout, we may need to call
`inline_content_sizes()` in order to compute the min/max-content sizes.
But this required a mutable reference in order the update the cache,
and in various places we already had mutable references.

So this switches the cache into a RwLock to avoid needing mutable refs.
Note OnceCell wouldn't work because it's not thread-safe.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2024-11-13 10:56:02 +01:00 committed by GitHub
parent c00804190c
commit 9102644470
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 76 additions and 74 deletions

View file

@ -772,7 +772,7 @@ impl<'a> TableLayout<'a> {
}
/// Compute CAPMIN: <https://drafts.csswg.org/css-tables/#capmin>
fn compute_caption_minimum_inline_size(&mut self, layout_context: &LayoutContext) -> Au {
fn compute_caption_minimum_inline_size(&self, layout_context: &LayoutContext) -> Au {
let containing_block = IndefiniteContainingBlock {
size: LogicalVec2 {
inline: AuOrAuto::Auto,
@ -784,7 +784,7 @@ impl<'a> TableLayout<'a> {
.captions
.iter()
.map(|caption| {
let mut context = caption.context.borrow_mut();
let context = caption.context.borrow();
context
.outer_inline_content_sizes(
layout_context,
@ -1605,7 +1605,7 @@ impl<'a> TableLayout<'a> {
}
fn layout_caption(
&mut self,
&self,
caption: &TableCaption,
table_pbm: &PaddingBorderMargin,
layout_context: &LayoutContext,
@ -2186,7 +2186,7 @@ impl<'a> TableLayout<'a> {
}
fn make_fragments_for_columns_and_column_groups(
&mut self,
&self,
dimensions: &TableAndTrackDimensions,
fragments: &mut Vec<Fragment>,
) {
@ -2630,7 +2630,7 @@ impl Table {
)
)]
pub(crate) fn inline_content_sizes(
&mut self,
&self,
layout_context: &LayoutContext,
constraint_space: &ConstraintSpace,
) -> InlineContentSizesResult {