Share packed native lists across copied boxes and shipouts

This commit is contained in:
gloamxun committed 2026-11-28 08:01:14 +08:00
1 parent ca3730338e
commit da48cf9cad
16 files changed
+157 -67

No files matched your search

@@ -152,12 +152,12 @@ pub(super) struct Collector {
pub usage: ResourceUsage,
macros: BTreeSet<usize>,
token_lists: BTreeSet<(usize, usize)>,
shared_diagnostic_lists: Option<BTreeSet<usize>>,
shared_lists: Option<BTreeSet<usize>>,
}
impl Collector {
pub fn for_capacity() -> Self {
Self {
shared_diagnostic_lists: Some(BTreeSet::new()),
shared_lists: Some(BTreeSet::new()),
..Self::default()
}
}
@@ -192,8 +192,9 @@ impl Collector {
pub fn native_box(&mut self, b: &NativeBox, o: Ownership) {
self.material(o).boxes += 1;
match &b.content {
BoxContent::Horizontal(v) => self.text(v, o),
BoxContent::Vertical(v) => self.vertical(v, o),
BoxContent::Horizontal(v) if self.visit_shared(v) => self.text(v, o),
BoxContent::Vertical(v) if self.visit_shared(v) => self.vertical(v.iter(), o),
_ => {}
}
self.shared_diagnostics(&b.diagnostic, o);
}
@@ -306,14 +307,18 @@ impl Collector {
self.text(&b.nodes, Ownership::Active);
self.usage.active_material.ligature_work_items += b.ligature_work_items();
}
fn visit_shared<T: ?Sized>(&mut self, list: &Arc<T>) -> bool {
self.shared_lists.as_mut().is_none_or(|seen| {
seen.insert(Arc::as_ptr(list).cast::<()>() as usize)
})
}
pub fn shared_diagnostics(
&mut self,
nodes: &Arc<[super::diagnostics::DiagnosticNode]>,
o: Ownership,
) {
if !nodes.is_empty() && self.shared_diagnostic_lists.as_mut()
.is_none_or(|seen| seen.insert(nodes.as_ptr() as usize))
{
if !nodes.is_empty() && self.visit_shared(nodes) {
self.diagnostics(nodes, o);
}
}