Truly independent web browser
LibWeb: Drop the per-pass inline item stash
Aliaksandr Kalenik848805fae3f3
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rsindex 40a6a4e5f2c..aed91575f5a 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs@@ -1357,14 +1357,6 @@ fn lay_out_entered_inline_box(sides}-/// The inline items a block container generated, kept for the later runs of the container in the same pass. Their-/// glyphs are shared, so that each run that reads them copies no glyphs.-#[derive(Clone)]-pub(crate) struct StashedInlineItems {- items: Vec<Item>,- entered_box_model_nodes: Vec<Node>,-}-struct SharedInlineItems {items: std::rc::Rc<[Item]>,entered_box_model_nodes: std::rc::Rc<[Node]>,@@ -1485,60 +1477,8 @@ impl InlineLevelIterator {context: &mut inline_formatting_context::InlineFormattingContext<'_>,atomic_sizing: AtomicInlineSizing,) -> Self {- let callbacks = context.callbacks;- match callbacks.inline_item_stash(context.containing_block) {- Some(stash) => Self::from_stash(context, stash),- None => PreparedInlineContent::for_block_container(callbacks, context.containing_block)- .resolve_items_for_run(context, atomic_sizing),- }- }-- fn from_stash(context: &inline_formatting_context::InlineFormattingContext<'_>, stash: StashedInlineItems) -> Self {- for node in &stash.entered_box_model_nodes {- lay_out_entered_inline_box(context, *node);- }- Self {- entered_box_model_nodes: stash.entered_box_model_nodes,- items: ItemQueue::Owned(stash.items.into_iter()),- items_kept_for_looking_ahead: 0,- }- }-- /// Element items and percentage inline-box margins and paddings depend on the run's available space.- fn is_independent_of_available_space(- &self,- context: &inline_formatting_context::InlineFormattingContext<'_>,- ) -> bool {- self.items- .as_slice()- .iter()- .all(|item| matches!(item.type_, ItemType::Text | ItemType::ForcedBreak))- && self.entered_box_model_nodes.iter().all(|node| {- let style = context.style(*node);- !style.margin_left().contains_percentage()- && !style.margin_right().contains_percentage()- && !style.padding_left().contains_percentage()- && !style.padding_right().contains_percentage()- })- }-- pub(crate) fn stash_for_reuse(self, context: &inline_formatting_context::InlineFormattingContext<'_>) {- if !self.is_independent_of_available_space(context) {- return;- }- let mut items = self.items.into_vec();- for glyphs in items.iter_mut().filter_map(|item| item.glyphs.as_mut()) {- if let libgfx_rust::text_layout::GlyphBuffer::Owned(owned) = &mut glyphs.glyphs {- glyphs.glyphs = libgfx_rust::text_layout::GlyphBuffer::Shared(std::mem::take(owned).into());- }- }- context.callbacks.store_inline_item_stash(- context.containing_block,- StashedInlineItems {- items,- entered_box_model_nodes: self.entered_box_model_nodes,- },- );+ PreparedInlineContent::for_block_container(context.callbacks, context.containing_block)+ .resolve_items_for_run(context, atomic_sizing)}pub(crate) fn next(&mut self) -> Option<Item> {diff --git a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rsindex f8db2c07bb1..89ff693d7ea 100644--- a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs+++ b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs@@ -132,9 +132,7 @@ pub(super) fn content_sizes_of_inline_content(&parent,);let iterator = inline_level_iterator::InlineLevelIterator::for_intrinsic_inline_size(&mut context);- let sizes = context.content_sizes_from_items(iterator.items());- iterator.stash_for_reuse(&context);- sizes+ context.content_sizes_from_items(iterator.items())};if !facts.lays_out_in_columns() {return sizes;diff --git a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs b/Libraries/LibWeb/Rust/src/layout/layout_pass.rsindex 5e7dd074de5..9c7d24e880f 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_pass.rs@@ -38,8 +38,7 @@ pub(crate) struct LayoutPass<'arena> {/// passes after them, or inside a run whose result is discarded, that run's own.intrinsic_size_caches: &'arena super::layout_node_arena::IntrinsicSizeCaches,/// Whether this pass view is inside a run whose result is discarded, which reads no memoized layout from before it- /// and keeps none: the run cache, the in-flow block cache, inline item stashes, prepared inline content and- /// intrinsic sizes.+ /// and keeps none: the run cache, the in-flow block cache, prepared inline content and intrinsic sizes.reads_no_memoized_layout: bool,/// The innermost of the position options the boxes this pass view lays out are laid out with.position_option_styles: Option<&'arena PositionOptionStyle<'arena>>,@@ -192,31 +191,6 @@ impl<'arena> LayoutPass<'arena> {self.reads_no_memoized_layout}- /// The inline items a block container generated earlier in the pass, which a run whose result is discarded does not- /// read.- pub(crate) fn inline_item_stash(- &self,- block_container: Node,- ) -> Option<super::inline_level_iterator::StashedInlineItems> {- if self.reads_no_memoized_layout {- return None;- }- self.scratch.inline_item_stash(block_container)- }-- /// Keeps the inline items `block_container` generated for its later runs in the pass, unless this pass view is- /// inside a run whose result is discarded.- pub(crate) fn store_inline_item_stash(- &self,- block_container: Node,- stash: super::inline_level_iterator::StashedInlineItems,- ) {- if self.reads_no_memoized_layout {- return;- }- self.scratch.store_inline_item_stash(block_container, stash);- }-/// Notes what the run this pass view was handed to found out for the host, or the pass outside any run.pub(crate) fn note_host_findings(&self, note: impl FnOnce(&mut super::run_state::HostFindings)) {note(&mut self.host_findings.borrow_mut());diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rsindex 1173b23f428..7ab6d7befac 100644--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs@@ -12,9 +12,6 @@ use super::*;pub(crate) struct LayoutScratch {/// The intrinsic sizes passes measured, kept for the passes after them.pub(super) intrinsic_size_caches: super::layout_node_arena::IntrinsicSizeCaches,- /// The inline items a block container generated, kept for its later runs in the same pass. The- /// items borrow fonts for the current pass, so the stashes are cleared when the pass ends.- inline_item_stashes: RefCell<HashMap<NodeSlotId, super::inline_level_iterator::StashedInlineItems>>,/// What the pass found out for the host outside any run, which its driver reports itself.pub(super) host_findings_outside_runs: RefCell<HostFindings>,/// The results of formatting context runs, kept for the runs after them in this pass and the passes after it.@@ -97,7 +94,6 @@ impl Default for LayoutScratch {fn default() -> Self {Self {intrinsic_size_caches: Default::default(),- inline_item_stashes: RefCell::new(HashMap::default()),host_findings_outside_runs: RefCell::new(HostFindings::default()),fc_run_cache_store: Default::default(),in_flow_block_cache_store: Default::default(),@@ -155,31 +151,15 @@ impl LayoutScratch {);}- pub(super) fn store_inline_item_stash(- &self,- block_container: NodeSlotId,- stash: super::inline_level_iterator::StashedInlineItems,- ) {- self.inline_item_stashes.borrow_mut().insert(block_container, stash);- }-- pub(super) fn inline_item_stash(- &self,- block_container: NodeSlotId,- ) -> Option<super::inline_level_iterator::StashedInlineItems> {- self.inline_item_stashes.borrow().get(&block_container).cloned()- }-/// What the pass found out outside any run, which its driver reports itself.pub(crate) fn take_host_findings_outside_runs(&self) -> HostFindings {std::mem::take(&mut self.host_findings_outside_runs.borrow_mut())}- /// Lets go of what the pass that just committed into `arena` kept for itself, and sweeps the run cache.+ /// Brings the run memos up to date with what the commit into `arena` did to their boxes, and sweeps the run cache.pub(crate) fn end_layout_pass(&self, arena: &mut LayoutNodeArena) {self.apply_memo_invalidations(arena);arena.sweep_stale_fc_run_cache_entries(&self.fc_run_cache_store);- self.inline_item_stashes.borrow_mut().clear();}}