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

@@ -791,9 +791,9 @@ fn empty_alignment_box(width: i64, horizontal: bool, span: Span) -> NativeBox {
depth: 0,
shift: 0,
content: if horizontal {
BoxContent::Horizontal(Vec::new())
BoxContent::Horizontal(Default::default())
} else {
BoxContent::Vertical(Vec::new())
BoxContent::Vertical(Default::default())
},
diagnostic: Default::default(),
setting: GlueSetting::default(),
@@ -857,7 +857,7 @@ fn set_alignment_cell(
};
match &cell.content {
BoxContent::Horizontal(v) => {
for n in v {
for n in v.iter() {
if let TextNode::Glue(g) | TextNode::FontSpace(g, _, _)
| TextNode::NamedGlue(g, _)
| TextNode::Leaders(LeaderGlue { glue: g, .. }) = n
@@ -867,7 +867,7 @@ fn set_alignment_cell(
}
}
BoxContent::Vertical(v) => {
for n in v {
for n in v.iter() {
if let NativeVerticalNode::Glue(g)
| NativeVerticalNode::NamedGlue(g, _)
| NativeVerticalNode::Leaders(LeaderGlue { glue: g, .. }) = n
@@ -937,16 +937,16 @@ fn set_alignment_row(
} else {
BoxKind::Vertical
};
let old = std::mem::replace(&mut row.content, BoxContent::Horizontal(Vec::new()));
let old = std::mem::replace(&mut row.content, BoxContent::Horizontal(Default::default()));
let mut cells: VecDeque<NativeBox> = match old {
BoxContent::Horizontal(v) => v
BoxContent::Horizontal(v) => std::sync::Arc::unwrap_or_clone(v)
.into_iter()
.filter_map(|n| match n {
TextNode::Box(b) => b.native_box.map(|b| *b),
_ => None,
})
.collect(),
BoxContent::Vertical(v) => v
BoxContent::Vertical(v) => std::sync::Arc::unwrap_or_clone(v)
.into_iter()
.filter_map(|n| match n {
NativeVerticalNode::Box(b) => Some(*b),
@@ -1014,10 +1014,10 @@ fn set_alignment_row(
if horizontal {
row.width = prototype.width;
row.diagnostic = super::super::diagnostics::text_nodes(&h).into();
row.content = BoxContent::Horizontal(h);
row.content = BoxContent::Horizontal(h.into());
} else {
row.height = prototype.height;
row.content = BoxContent::Vertical(v);
row.content = BoxContent::Vertical(v.into());
}
Ok(())
}
@@ -1031,7 +1031,7 @@ fn mark_unset(b: &mut NativeBox, span: u8) -> Result<(), String> {
};
match &b.content {
BoxContent::Horizontal(v) => {
for n in v {
for n in v.iter() {
if let TextNode::Glue(g) | TextNode::FontSpace(g, _, _)
| TextNode::NamedGlue(g, _)
| TextNode::Leaders(LeaderGlue { glue: g, .. }) = n
@@ -1041,7 +1041,7 @@ fn mark_unset(b: &mut NativeBox, span: u8) -> Result<(), String> {
}
}
BoxContent::Vertical(v) => {
for n in v {
for n in v.iter() {
if let NativeVerticalNode::Glue(g)
| NativeVerticalNode::NamedGlue(g, _)
| NativeVerticalNode::Leaders(LeaderGlue { glue: g, .. }) = n
@@ -166,9 +166,11 @@ impl Executor {
.expect("unhbox starts an actual paragraph")
.nodes
.extend(
nodes.into_iter().filter(|node| !matches!(node, TextNode::MarginKern { .. })),
Arc::unwrap_or_clone(nodes)
.into_iter()
.filter(|node| !matches!(node, TextNode::MarginKern { .. })),
),
BoxContent::Vertical(nodes) => self.append_unboxed_vertical(nodes),
BoxContent::Vertical(nodes) => self.append_unboxed_vertical(Arc::unwrap_or_clone(nodes)),
}
Ok(())
}
@@ -442,7 +444,7 @@ impl Executor {
let max_depth = self.read_parameter(Parameter::Splitmaxdepth).width();
let skip = self.read_parameter(Parameter::Splittopskip).glue();
let original = self.state.take_box(index).unwrap();
let BoxContent::Vertical(mut nodes) = original.content else {
let BoxContent::Vertical(nodes) = original.content else {
unreachable!()
};
let cut = super::super::vertical_break::find_break(
@@ -453,6 +455,7 @@ impl Executor {
self.limits.steps,
)
.map_err(|e| self.error(e, span))?;
let mut nodes = Arc::unwrap_or_clone(nodes);
let tail = nodes.split_off(cut.index);
self.collect_split_marks(&nodes)?;
let save = self.read_parameter(Parameter::Savingvdiscards).width() > 0;
@@ -520,7 +523,7 @@ impl Executor {
height: 0,
depth: 0,
shift: 0,
content: BoxContent::Horizontal(Vec::new()),
content: BoxContent::Horizontal(Default::default()),
diagnostic: Default::default(),
setting: GlueSetting::default(),
interword_runs: Vec::new(),
@@ -827,7 +830,7 @@ impl Executor {
let BoxContent::Vertical(nodes) = b.content else {
unreachable!("vadjust owns a vertical list");
};
let adjustment = NativeAdjustment { pre, nodes };
let adjustment = NativeAdjustment { pre, nodes: Arc::unwrap_or_clone(nodes) };
if let Some(math) = self.math.last_mut() {
math.nodes.push(MathNode::Adjustment(adjustment));
} else {
@@ -849,7 +852,7 @@ impl Executor {
split_top,
split_depth,
float_cost,
nodes,
nodes: Arc::unwrap_or_clone(nodes),
span: frame.span,
};
if let Some(math) = self.math.last_mut() {
@@ -24,7 +24,7 @@ impl Executor {
return Ok(());
}
// Packing can move existing lists or replace an old register. Recount
// actual storage here, including a shared diagnostic allocation once.
// actual storage here, counting each shared list allocation once.
let usage = self.collect_usage(shipping, None, Collector::for_capacity());
self.material_charge = usage
.active_material