From 0faed068d130bce8a0448632c2f342dc2a62fa0e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 16 May 2026 21:11:48 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Remove=20intermediate=20allocations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced string-based splits with char-based splits and removed intermediate Vec allocations in `xdk-build/src/python.rs`. Replaced intermediate Vec allocation and `.join("")` with direct `.collect::()` in `xdk-lib/src/casing.rs`. Added inline comments explaining the optimizations. Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com> --- xdk-build/src/python.rs | 17 +++++++---------- xdk-lib/src/casing.rs | 7 ++----- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/xdk-build/src/python.rs b/xdk-build/src/python.rs index 1d15d6f0..3badaf0b 100644 --- a/xdk-build/src/python.rs +++ b/xdk-build/src/python.rs @@ -159,16 +159,13 @@ 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()); - } - }); + // Bolt optimization: use char split and direct iteration/pattern matching to avoid Vec allocations + stdout.split('\n').for_each(|line| { + let mut parts = line.split(' '); + if let (Some(part1), Some(part2), None) = (parts.next(), parts.next(), parts.next()) { + log_info!("{} {}", part1, part2.magenta()); + } + }); println!(); } diff --git a/xdk-lib/src/casing.rs b/xdk-lib/src/casing.rs index 6463487e..f5cafbc5 100644 --- a/xdk-lib/src/casing.rs +++ b/xdk-lib/src/casing.rs @@ -29,11 +29,8 @@ impl Casing { result } } - Casing::Pascal => words - .iter() - .map(|w| pascal_case(w)) - .collect::>() - .join(""), + // Bolt optimization: collect directly to String instead of intermediate Vec + join + Casing::Pascal => words.iter().map(|w| pascal_case(w)).collect::(), Casing::Kebab => words.join("-").to_lowercase(), Casing::ScreamingSnake => words.join("_").to_uppercase(), }