From d5a6b7518d921894a7315db8267ebde738f30c10 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2026 21:15:16 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20string=20allocat?= =?UTF-8?q?ions=20in=20casing=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com> --- .jules/bolt.md | 3 +++ xdk-lib/src/casing.rs | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..06cb026e --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-24 - Avoid string collection allocations +**Learning:** Rust's `.collect::>().join("")` allocates an unnecessary intermediate vector, and `.to_lowercase().collect::()` misses out on `Display` optimizations compared to `.to_lowercase().to_string()`. +**Action:** Use `.collect::()` directly when concatenating strings from an iterator, and `.to_string()` for char transformations to save memory and CPU cycles. diff --git a/xdk-lib/src/casing.rs b/xdk-lib/src/casing.rs index 6463487e..6d860bab 100644 --- a/xdk-lib/src/casing.rs +++ b/xdk-lib/src/casing.rs @@ -32,8 +32,9 @@ impl Casing { Casing::Pascal => words .iter() .map(|w| pascal_case(w)) - .collect::>() - .join(""), + // Bolt optimization: avoiding `.collect::>().join("")` + // prevents allocating an intermediate vector just to concatenate strings. + .collect::(), Casing::Kebab => words.join("-").to_lowercase(), Casing::ScreamingSnake => words.join("_").to_uppercase(), }