From 42e9d2450e69ab94adbef9458389e836cf38e8ca Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 19 Jun 2020 15:38:15 +0200 Subject: [PATCH] Parallelize `BlockContainer::inline_content_sizes` --- components/layout_2020/flow/mod.rs | 18 +++++++----------- components/layout_2020/sizing.rs | 8 +++++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index 205acad83dde..de22f1a427d4 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -141,17 +141,13 @@ impl BlockContainer { containing_block_writing_mode: WritingMode, ) -> ContentSizes { match &self { - Self::BlockLevelBoxes(boxes) => { - let mut content_sizes = ContentSizes::zero(); - for box_ in boxes { - content_sizes.max_assign( - &box_ - .borrow_mut() - .inline_content_sizes(layout_context, containing_block_writing_mode), - ); - } - content_sizes - }, + Self::BlockLevelBoxes(boxes) => boxes + .par_iter() + .map(|box_| { + box_.borrow_mut() + .inline_content_sizes(layout_context, containing_block_writing_mode) + }) + .reduce(ContentSizes::zero, ContentSizes::max), Self::InlineFormattingContext(context) => { context.inline_content_sizes(layout_context, containing_block_writing_mode) }, diff --git a/components/layout_2020/sizing.rs b/components/layout_2020/sizing.rs index ec07861c3747..ccf60ceb9338 100644 --- a/components/layout_2020/sizing.rs +++ b/components/layout_2020/sizing.rs @@ -33,9 +33,11 @@ impl ContentSizes { } } - pub fn max_assign(&mut self, other: &Self) { - self.min_content.max_assign(other.min_content); - self.max_content.max_assign(other.max_content); + pub fn max(self, other: Self) -> Self { + Self { + min_content: self.min_content.max(other.min_content), + max_content: self.max_content.max(other.max_content), + } } /// Relevant to outer intrinsic inline sizes, for percentages from padding and margin.