mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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:
parent
c00804190c
commit
9102644470
9 changed files with 76 additions and 74 deletions
|
@ -891,7 +891,7 @@ impl FloatBox {
|
|||
/// the float containing block formatting context. A later step adjusts the position
|
||||
/// to be relative to the containing block.
|
||||
pub fn layout(
|
||||
&mut self,
|
||||
&self,
|
||||
layout_context: &LayoutContext,
|
||||
positioning_context: &mut PositioningContext,
|
||||
containing_block: &ContainingBlock,
|
||||
|
|
|
@ -1656,7 +1656,7 @@ impl InlineFormattingContext {
|
|||
}
|
||||
|
||||
for item in self.inline_items.iter() {
|
||||
let item = &mut *item.borrow_mut();
|
||||
let item = &*item.borrow();
|
||||
|
||||
// Any new box should flush a pending hard line break.
|
||||
if !matches!(item, InlineItem::EndInlineBox) {
|
||||
|
@ -1684,7 +1684,7 @@ impl InlineFormattingContext {
|
|||
},
|
||||
));
|
||||
},
|
||||
InlineItem::OutOfFlowFloatBox(ref mut float_box) => {
|
||||
InlineItem::OutOfFlowFloatBox(ref float_box) => {
|
||||
float_box.layout_into_line_items(&mut layout);
|
||||
},
|
||||
}
|
||||
|
@ -1915,7 +1915,7 @@ impl InlineContainerState {
|
|||
|
||||
impl IndependentFormattingContext {
|
||||
fn layout_into_line_items(
|
||||
&mut self,
|
||||
&self,
|
||||
layout: &mut InlineFormattingContextLayout,
|
||||
offset_in_text: usize,
|
||||
bidi_level: Level,
|
||||
|
@ -2071,7 +2071,7 @@ impl IndependentFormattingContext {
|
|||
}
|
||||
|
||||
impl FloatBox {
|
||||
fn layout_into_line_items(&mut self, layout: &mut InlineFormattingContextLayout) {
|
||||
fn layout_into_line_items(&self, layout: &mut InlineFormattingContextLayout) {
|
||||
let fragment = self.layout(
|
||||
layout.layout_context,
|
||||
layout.positioning_context,
|
||||
|
@ -2211,7 +2211,7 @@ impl<'layout_data> ContentSizesComputation<'layout_data> {
|
|||
inline_formatting_context: &InlineFormattingContext,
|
||||
) -> InlineContentSizesResult {
|
||||
for inline_item in inline_formatting_context.inline_items.iter() {
|
||||
self.process_item(&mut inline_item.borrow_mut(), inline_formatting_context);
|
||||
self.process_item(&inline_item.borrow(), inline_formatting_context);
|
||||
}
|
||||
|
||||
self.forced_line_break();
|
||||
|
@ -2223,7 +2223,7 @@ impl<'layout_data> ContentSizesComputation<'layout_data> {
|
|||
|
||||
fn process_item(
|
||||
&mut self,
|
||||
inline_item: &mut InlineItem,
|
||||
inline_item: &InlineItem,
|
||||
inline_formatting_context: &InlineFormattingContext,
|
||||
) {
|
||||
match inline_item {
|
||||
|
|
|
@ -370,10 +370,10 @@ fn calculate_inline_content_size_for_block_level_boxes(
|
|||
containing_block: &IndefiniteContainingBlock,
|
||||
) -> InlineContentSizesResult {
|
||||
let get_box_info = |box_: &ArcRefCell<BlockLevelBox>| {
|
||||
match &mut *box_.borrow_mut() {
|
||||
match &*box_.borrow() {
|
||||
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(_) |
|
||||
BlockLevelBox::OutsideMarker { .. } => None,
|
||||
BlockLevelBox::OutOfFlowFloatBox(ref mut float_box) => {
|
||||
BlockLevelBox::OutOfFlowFloatBox(ref float_box) => {
|
||||
let inline_content_sizes_result = float_box.contents.outer_inline_content_sizes(
|
||||
layout_context,
|
||||
containing_block,
|
||||
|
@ -404,7 +404,7 @@ fn calculate_inline_content_size_for_block_level_boxes(
|
|||
// Instead, we treat it like an independent block with 'clear: both'.
|
||||
Some((inline_content_sizes_result, Float::None, Clear::Both))
|
||||
},
|
||||
BlockLevelBox::Independent(ref mut independent) => {
|
||||
BlockLevelBox::Independent(ref independent) => {
|
||||
let inline_content_sizes_result = independent.outer_inline_content_sizes(
|
||||
layout_context,
|
||||
containing_block,
|
||||
|
@ -606,7 +606,7 @@ fn layout_block_level_children_in_parallel(
|
|||
.map(|child_box| {
|
||||
let mut child_positioning_context =
|
||||
PositioningContext::new_for_subtree(collects_for_nearest_positioned_ancestor);
|
||||
let fragment = child_box.borrow_mut().layout(
|
||||
let fragment = child_box.borrow().layout(
|
||||
layout_context,
|
||||
&mut child_positioning_context,
|
||||
containing_block,
|
||||
|
@ -646,7 +646,7 @@ fn layout_block_level_children_sequentially(
|
|||
.iter()
|
||||
.map(|child_box| {
|
||||
let positioning_context_length_before_layout = positioning_context.len();
|
||||
let mut fragment = child_box.borrow_mut().layout(
|
||||
let mut fragment = child_box.borrow().layout(
|
||||
layout_context,
|
||||
positioning_context,
|
||||
containing_block,
|
||||
|
@ -670,7 +670,7 @@ fn layout_block_level_children_sequentially(
|
|||
|
||||
impl BlockLevelBox {
|
||||
fn layout(
|
||||
&mut self,
|
||||
&self,
|
||||
layout_context: &LayoutContext,
|
||||
positioning_context: &mut PositioningContext,
|
||||
containing_block: &ContainingBlock,
|
||||
|
@ -1997,7 +1997,7 @@ fn block_size_is_zero_or_intrinsic(size: &StyleSize, containing_block: &Containi
|
|||
|
||||
impl IndependentFormattingContext {
|
||||
pub(crate) fn layout_float_or_atomic_inline(
|
||||
&mut self,
|
||||
&self,
|
||||
layout_context: &LayoutContext,
|
||||
child_positioning_context: &mut PositioningContext,
|
||||
containing_block: &ContainingBlock,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue