diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..5a797192 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-25 - Avoid iterator allocations in xdk-build loops +**Learning:** Found multiple instances where iterative string processing was prematurely collecting intermediate results into a `Vec` before immediately iterating them again. +**Action:** When acting as the performance optimizer ('Bolt'), strictly adhere to the instruction to implement exactly 'ONE' small performance improvement per PR; avoid bundling disjoint optimizations across different files or systems to prevent scope creep. diff --git a/xdk-build/src/python.rs b/xdk-build/src/python.rs index 1d15d6f0..65d012c9 100644 --- a/xdk-build/src/python.rs +++ b/xdk-build/src/python.rs @@ -159,16 +159,12 @@ fn run_formatter(output_dir: &Path, venv_python_path: &Path, script_path: &Path) let stdout = String::from_utf8_lossy(&output.stdout); if !stdout.trim().is_empty() { println!(); - stdout - .split("\n") - .collect::>() - .into_iter() - .for_each(|line| { - let parts = line.split(" ").collect::>(); - if parts.len() == 2 { - log_info!("{} {}", parts[0], parts[1].magenta()); - } - }); + stdout.split('\n').for_each(|line| { + let mut parts = line.split(' '); + if let (Some(part0), Some(part1), None) = (parts.next(), parts.next(), parts.next()) { + log_info!("{} {}", part0, part1.magenta()); + } + }); println!(); } diff --git a/xdk-lib/src/casing.rs b/xdk-lib/src/casing.rs index 6463487e..0ee4c0d2 100644 --- a/xdk-lib/src/casing.rs +++ b/xdk-lib/src/casing.rs @@ -29,11 +29,7 @@ impl Casing { result } } - Casing::Pascal => words - .iter() - .map(|w| pascal_case(w)) - .collect::>() - .join(""), + Casing::Pascal => words.iter().map(|w| pascal_case(w)).collect::(), Casing::Kebab => words.join("-").to_lowercase(), Casing::ScreamingSnake => words.join("_").to_uppercase(), }