Compare commits

..
6 changed files with 29 additions and 27 deletions
+2 -2
View File
File diff suppressed because one or more lines are too long
+17
View File
@@ -58,6 +58,23 @@ mod tests {
assert!(t.rows.iter().all(|r| r.len() <= 64), "a row grew past the column cap");
}
#[test]
fn insert_covered_skips_full_rows_without_walking_them() {
// 50,000 spanning cells over a 50,000-cell row: each walked the row below to its grid
// column before finding it full (billions of steps). A full row is now skipped at once.
let n = 50_000;
let mut t = FTable {
rows: vec![vec![Cell { rowspan: 2, ..Default::default() }; n], vec![Cell::default(); n]],
widths: Vec::new(),
borderless: false,
};
let start = std::time::Instant::now();
t.insert_covered();
assert!(start.elapsed() < std::time::Duration::from_secs(10), "{:?}", start.elapsed());
assert_eq!(t.rows[1].len(), n, "a full row takes no covered cell");
assert!(t.rows[1].iter().all(|c| !c.covered));
}
#[test]
fn base64_round_trip() {
for data in [&b""[..], b"f", b"fo", b"foo", b"foob", b"fooba", b"foobar", &[0, 255, 128, 7]] {
+3 -10
View File
@@ -118,10 +118,6 @@ struct Builder<'a> {
revs: std::collections::HashMap<(u8, RevMark), u32>,
/// Link and font bytes given to runs so far ([`MAX_RUN_STRINGS`]).
run_strings: usize,
/// The ids the next list's abstract and concrete numbering take: past every id in `doc`,
/// found once rather than by a scan of every numbering per list.
next_abstract: u32,
next_num: u32,
}
fn rev_key(kind: RevisionKind) -> u8 {
@@ -141,9 +137,7 @@ impl<'a> Builder<'a> {
revs.entry((rev_key(r.kind), mark)).or_insert(i as u32);
}
}
let next_abstract = doc.numbering.abstracts.iter().map(|a| a.id.saturating_add(1)).max().unwrap_or(0);
let next_num = doc.numbering.nums.iter().map(|n| n.id.saturating_add(1)).max().unwrap_or(1).max(1);
Builder { doc, revs, run_strings: 0, next_abstract, next_num }
Builder { doc, revs, run_strings: 0 }
}
/// The document revision for a tracked change, added the first time it is seen.
@@ -297,10 +291,9 @@ impl<'a> Builder<'a> {
})
.collect();
let numbering = &mut self.doc.numbering;
let (aid, nid) = (self.next_abstract, self.next_num);
self.next_abstract = aid.saturating_add(1);
self.next_num = nid.saturating_add(1);
let aid = numbering.abstracts.iter().map(|a| a.id + 1).max().unwrap_or(0);
numbering.abstracts.push(AbstractNum { id: aid, name: None, levels, ..Default::default() });
let nid = numbering.nums.iter().map(|n| n.id + 1).max().unwrap_or(1).max(1);
numbering.nums.push(Num { id: nid, abstract_id: aid, ..Default::default() });
nid
}
+6 -3
View File
@@ -418,6 +418,11 @@ impl FTable {
return;
}
let Some(row) = self.rows.get_mut(r + k) else { break };
// A full row takes no covered cell: checked before it is walked, so a
// wide row isn't scanned for every span above it.
if row.len() >= 64 {
continue;
}
// Find the index in that row at grid column `g`.
let mut x = 0usize;
let mut at = row.len();
@@ -428,9 +433,7 @@ impl FTable {
}
x += cc.colspan.clamp(1, 63) as usize;
}
if row.len() < 64 {
row.insert(at, Cell { colspan: span as u32, covered: true, ..Default::default() });
}
row.insert(at, Cell { colspan: span as u32, covered: true, ..Default::default() });
}
}
g += span;
-11
View File
@@ -1019,14 +1019,3 @@ fn latex_export_keeps_repeated_spaces() {
let d = crate::import("tex", tex.as_bytes()).unwrap().unwrap();
assert_eq!(para_texts(&d), vec!["a b c".to_string()]);
}
#[test]
fn many_imported_lists_take_fresh_numbering_ids_in_turn() {
// Each list found its ids by scanning every numbering made before it (quadratic in lists).
let md: String = (0..4000).map(|i| if i % 2 == 0 { "- a\n\n" } else { "1. b\n\n" }).collect();
let d = import("md", md.as_bytes()).expect("handled").expect("import");
let ids: Vec<u32> = d.numbering.nums.iter().map(|n| n.id).collect();
assert_eq!(ids, (1..=4000).collect::<Vec<u32>>());
let abstracts: Vec<u32> = d.numbering.abstracts.iter().map(|a| a.id).collect();
assert_eq!(abstracts, (0..4000).collect::<Vec<u32>>());
}
+1 -1
View File
File diff suppressed because one or more lines are too long