From 7bcb1a9da2e0a677aa083e07ca561812a4b8021a Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Fri, 24 Apr 2026 01:15:40 -0700 Subject: [PATCH] Code review Co-authored-by: Copilot --- Cargo.toml | 2 ++ libraries/ipsum/src/lib.rs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bbf3097a5a..d04e747a93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "frontend/wrapper", "libraries/dyn-any", "libraries/math-parser", + "libraries/ipsum", "node-graph/libraries/*", "node-graph/nodes/*", "node-graph/nodes/raster/shaders", @@ -33,6 +34,7 @@ default-members = [ "frontend/wrapper", "libraries/dyn-any", "libraries/math-parser", + "libraries/ipsum", "node-graph/graph-craft", "node-graph/interpreted-executor", "node-graph/node-macro", diff --git a/libraries/ipsum/src/lib.rs b/libraries/ipsum/src/lib.rs index ff520f53b7..4030bd1455 100644 --- a/libraries/ipsum/src/lib.rs +++ b/libraries/ipsum/src/lib.rs @@ -336,20 +336,19 @@ fn seed_chain(out: &mut Output, opener_words_used: usize, opener_ended_with_brea /// Pick the next successor for this step, applying unit-specific biasing. fn pick_next(followers: &[u16], at_final_word: bool, total_unit: Unit, out: &Output, total_length: usize, rand_index: &mut impl FnMut(usize) -> usize) -> u16 { if at_final_word { - // For the Words unit's final real word, prefer a successor that ends a sentence - let enders: Vec = followers.iter().copied().filter(|&w| word(w).ends_with(SENTENCE_ENDERS)).collect(); - if !enders.is_empty() { - return enders[rand_index(enders.len())]; + let mut enders = followers.iter().copied().filter(|&w| word(w).ends_with(SENTENCE_ENDERS)); + let count = enders.clone().count(); + if count > 0 { + return enders.nth(rand_index(count)).unwrap(); } } if total_unit == Unit::Characters { - // Prefer a successor whose emission fits the remaining character budget so the chain - // can land closer to the exact target without needing truncation let remaining = total_length.saturating_sub(out.output.len()); - let fits: Vec = followers.iter().copied().filter(|&w| emission_byte_cost(word(w), &out.output) <= remaining).collect(); - if !fits.is_empty() { - return fits[rand_index(fits.len())]; + let mut fits = followers.iter().copied().filter(|&w| emission_byte_cost(word(w), &out.output) <= remaining); + let count = fits.clone().count(); + if count > 0 { + return fits.nth(rand_index(count)).unwrap(); } }