From d53a740be1a179fd0f1e126a27d2110dfffc5df8 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Sun, 15 Nov 2026 10:25:09 +0100 Subject: [PATCH] #6757: lay out a paragraph over many pages in linear time Each page's piece of a paragraph walked every line of the paragraph in place_objects to find the pictures and shapes to draw with it, skipping all but its own lines and the late-float anchor lines. A paragraph over many pages was quadratic in its lines. A later piece now walks only its own lines and the late-float anchor lines, in the same order. unequal_formats_lay_out_in_linear_time reads 8.0x for 8x the runs in a debug build, down from 15.0x, so it no longer fails in the slower SonarCloud coverage build. Co-Authored-By: Claude Opus 5.5 --- crates/layout/src/floats.rs | 16 +++++++++++----- crates/layout/src/tests/linear.rs | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/crates/layout/src/floats.rs b/crates/layout/src/floats.rs index 933c09c321..89264cbb27 100644 --- a/crates/layout/src/floats.rs +++ b/crates/layout/src/floats.rs @@ -718,12 +718,18 @@ pub(crate) fn place_objects(ctx: &mut Ctx, req: &ObjectPlacement) -> (Vec Document { + let mut d = Document::from_text(""); + d.body = vec![wordcraft_doc::para_block(Paragraph::with_text(&"x\n".repeat(n), CharProps::default()))]; + d +} + +/// The piece of a long paragraph on each page looked through every line of the paragraph for the +/// pictures and shapes to draw with it (#6757). +#[test] +fn a_paragraph_over_many_pages_lays_out_in_linear_time() { + let pages = lay(&many_lines(SCALE * 400), &LayoutOptions::default()).pages.len(); + assert!(pages > 40, "the paragraph runs over many pages: {pages}"); + assert_layout_linear("a paragraph over many pages", 400, many_lines, &LayoutOptions::default()); +} + /// A table of `n` rows of 60 cells, each row exactly half a point high, so every cell clips its /// (empty) paragraph and the whole table fits on the first page. fn clipped_table(n: usize) -> Document {