Skip to content

Truly independent web browser

LibWeb: Leave out what a run hands past its root when there is nothing

Aliaksandr Kalenik6423b8c99f3e
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 63d8c823e2a..6b41087d02d 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -312,7 +312,7 @@ impl FcRunCacheEntry {
let Some(root) = self.outputs.root.as_ref() else {
return false;
};
- if !root.payloads_past_run.pending_abspos.is_empty() || !arena.paintable_row_is_populated(box_) {
+ if !root.payloads_past_run().pending_abspos.is_empty() || !arena.paintable_row_is_populated(box_) {
return false;
}
let (content_inline_size, content_block_size) = self.root_content_size_as_its_parent_holds_it();
@@ -903,7 +903,7 @@ pub(super) fn run_observes_root_block_padding(
|| outputs
.root
.as_ref()
- .is_none_or(|root| !root.payloads_past_run.is_empty())
+ .is_none_or(|root| root.payloads_past_run.is_some())
}
#[cfg(test)]
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index 698768c8c1e..60f68182a86 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -874,8 +874,8 @@ impl RunContents {
&mut scoped_descendants,
);
}
- RunRootFragment {
- fragment: snapshot_fragment(
+ RunRootFragment::new(
+ snapshot_fragment(
callbacks,
node,
scoped_descendants,
@@ -884,7 +884,7 @@ impl RunContents {
root_payloads,
),
payloads_past_run,
- }
+ )
}
}
@@ -894,17 +894,35 @@ impl RunContents {
#[must_use = "a child's fragments are lost unless its placement takes them"]
pub(crate) struct RunRootFragment {
pub(crate) fragment: std::sync::Arc<Fragment>,
- pub(crate) payloads_past_run: PayloadsPastRun,
+ pub(crate) payloads_past_run: Option<Box<PayloadsPastRun>>,
}
+static NO_PAYLOADS_PAST_RUN: PayloadsPastRun = PayloadsPastRun {
+ pending_abspos: Vec::new(),
+ anchor_candidates: Vec::new(),
+ inline_containing_block_rects: Vec::new(),
+ abspos_containing_block_info: Vec::new(),
+};
+
impl RunRootFragment {
+ pub(crate) fn new(fragment: std::sync::Arc<Fragment>, payloads_past_run: PayloadsPastRun) -> Self {
+ Self {
+ fragment,
+ payloads_past_run: (!payloads_past_run.is_empty()).then(|| Box::new(payloads_past_run)),
+ }
+ }
+
/// The root fragment of a run that hands nothing past `fragment`.
pub(crate) fn propagating_nothing(fragment: std::sync::Arc<Fragment>) -> Self {
Self {
fragment,
- payloads_past_run: PayloadsPastRun::default(),
+ payloads_past_run: None,
}
}
+
+ pub(crate) fn payloads_past_run(&self) -> &PayloadsPastRun {
+ self.payloads_past_run.as_deref().unwrap_or(&NO_PAYLOADS_PAST_RUN)
+ }
}
#[derive(Clone, Copy)]
@@ -1547,19 +1565,26 @@ impl RunFragmentBuilder {
"a child run's root and an open pending fragment both carry children for slot {slot}"
);
pending_fragment.arrived = Some(root.fragment);
+ let Some(payloads_past_run) = root.payloads_past_run else {
+ return;
+ };
+ let PayloadsPastRun {
+ pending_abspos,
+ anchor_candidates,
+ inline_containing_block_rects,
+ abspos_containing_block_info,
+ } = *payloads_past_run;
pending_fragment
.pending_abspos
- .extend(root.payloads_past_run.pending_abspos.into_iter().map(|mut entry| {
+ .extend(pending_abspos.into_iter().map(|mut entry| {
formatting_context::resolve_pending_abspos_containing_block(callbacks, &mut entry, self.root_node);
entry
}));
- pending_fragment
- .anchor_candidates
- .extend(root.payloads_past_run.anchor_candidates);
+ pending_fragment.anchor_candidates.extend(anchor_candidates);
pending_fragment
.inline_containing_block_rects
- .extend(root.payloads_past_run.inline_containing_block_rects);
- inner.receive_abspos_containing_block_info(root.payloads_past_run.abspos_containing_block_info);
+ .extend(inline_containing_block_rects);
+ inner.receive_abspos_containing_block_info(abspos_containing_block_info);
}
#[allow(clippy::too_many_arguments)]
diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
index fc8f51ddbfa..a08e8d8ce39 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
@@ -222,17 +222,17 @@ impl ComparedLayouts<'_> {
);
assert!(
same_elements_in_any_order(
- &checked_root.payloads_past_run.pending_abspos,
- &reference_root.payloads_past_run.pending_abspos
+ &checked_root.payloads_past_run().pending_abspos,
+ &reference_root.payloads_past_run().pending_abspos
) && same_elements_in_any_order(
- &checked_root.payloads_past_run.anchor_candidates,
- &reference_root.payloads_past_run.anchor_candidates
+ &checked_root.payloads_past_run().anchor_candidates,
+ &reference_root.payloads_past_run().anchor_candidates
) && same_elements_in_any_order(
- &checked_root.payloads_past_run.inline_containing_block_rects,
- &reference_root.payloads_past_run.inline_containing_block_rects
+ &checked_root.payloads_past_run().inline_containing_block_rects,
+ &reference_root.payloads_past_run().inline_containing_block_rects
) && same_elements_in_any_order(
- &checked_root.payloads_past_run.abspos_containing_block_info,
- &reference_root.payloads_past_run.abspos_containing_block_info
+ &checked_root.payloads_past_run().abspos_containing_block_info,
+ &reference_root.payloads_past_run().abspos_containing_block_info
),
"{checked} propagates payloads {reference} does not"
);