From 41e3c321e51840a5ce65fede125ed3d951c51069 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Thu, 12 Dec 2024 02:37:05 +0100 Subject: [PATCH] Make sure to cache `inline_content_sizes()` (#34586) The refactoring in 264c0f972fd1a732ee1d1490d78a1d26a65c6f5f stopped caching the `inline_content_sizes()` calls from: - `FlexItemBox::layout_for_block_content_size()` - `IndependentFormattingContext::layout_float_or_atomic_inline()` - `TaffyContainerContext::compute_child_layout()` Also, the call from `OutsideMarker::layout()` was never cached. This patch caches all of them. It's not clear at all which `inline_content_sizes()` are cached and which aren't, so I plan to improve the situation in a follow-up. Signed-off-by: Oriol Brufau --- components/layout_2020/flexbox/layout.rs | 2 +- components/layout_2020/flow/construct.rs | 2 +- components/layout_2020/flow/mod.rs | 21 +++++++++++++-------- components/layout_2020/taffy/layout.rs | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs index 27831a0646a..9c750b9b0d1 100644 --- a/components/layout_2020/flexbox/layout.rs +++ b/components/layout_2020/flexbox/layout.rs @@ -2799,7 +2799,7 @@ impl FlexItemBox { style.writing_mode, non_replaced.preferred_aspect_ratio(), ); - non_replaced + self.independent_formatting_context .inline_content_sizes( flex_context.layout_context, &constraint_space, diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs index 6a7545305a9..d14d4347dfa 100644 --- a/components/layout_2020/flow/construct.rs +++ b/components/layout_2020/flow/construct.rs @@ -713,7 +713,7 @@ where ); ArcRefCell::new(BlockLevelBox::OutsideMarker(OutsideMarker { marker_style, - list_item_style: info.style.clone(), + base: LayoutBoxBase::new(info.into(), info.style.clone()), block_container, })) }, diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index 730dac3e6a7..d8f7a5f570c 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -225,12 +225,15 @@ pub(crate) struct CollapsibleWithParentStartMargin(bool); pub(crate) struct OutsideMarker { #[serde(skip_serializing)] pub marker_style: Arc, - #[serde(skip_serializing)] - pub list_item_style: Arc, + pub base: LayoutBoxBase, pub block_container: BlockContainer, } impl OutsideMarker { + fn list_item_style(&self) -> &ComputedValues { + &self.base.style + } + fn layout( &self, layout_context: &LayoutContext<'_>, @@ -243,9 +246,10 @@ impl OutsideMarker { &self.marker_style, None, /* TODO: support preferred aspect ratios on non-replaced boxes */ ); - let content_sizes = self - .block_container - .inline_content_sizes(layout_context, &constraint_space); + let content_sizes = self.base.inline_content_sizes(&constraint_space, || { + self.block_container + .inline_content_sizes(layout_context, &constraint_space) + }); let containing_block_for_children = ContainingBlock { size: ContainingBlockSize { inline: content_sizes.sizes.max_content, @@ -292,7 +296,9 @@ impl OutsideMarker { // TODO: This is the wrong containing block, as it should be the containing block of the // parent of this list item. What this means in practice is that the writing mode could be // wrong and padding defined as a percentage will be resolved incorrectly. - let pbm_of_list_item = self.list_item_style.padding_border_margin(containing_block); + let pbm_of_list_item = self + .list_item_style() + .padding_border_margin(containing_block); let content_rect = LogicalRect { start_corner: LogicalVec2 { inline: -max_inline_size - @@ -2098,8 +2104,7 @@ impl IndependentFormattingContext { writing_mode, non_replaced.preferred_aspect_ratio(), ); - non_replaced - .inline_content_sizes(layout_context, &constraint_space) + self.inline_content_sizes(layout_context, &constraint_space) .sizes }); diff --git a/components/layout_2020/taffy/layout.rs b/components/layout_2020/taffy/layout.rs index 2c6d4d084e8..d0e178e342b 100644 --- a/components/layout_2020/taffy/layout.rs +++ b/components/layout_2020/taffy/layout.rs @@ -232,7 +232,7 @@ impl taffy::LayoutPartialTree for TaffyContainerContext<'_> { preferred_aspect_ratio: non_replaced.preferred_aspect_ratio(), }; - let result = non_replaced + let result = independent_context .inline_content_sizes(self.layout_context, &constraint_space); let adjusted_available_space = inputs .available_space