From 9a5fc8168ad9aa79f2f33ff224349bf8135688fd Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2026 21:30:15 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20optimize=20string=20allocations=20in=20Casing=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced `.collect::>().join("")` with `.collect::()` for `Casing::Pascal` to avoid intermediate vector heap allocations. Replaced `first.to_lowercase().collect::()` with `first.to_lowercase().to_string()` in `camel_case` to leverage the `Display` implementation and avoid iterator collection overhead. Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com> --- .jules/bolt.md | 7 +++++++ xdk-lib/src/casing.rs | 8 ++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..f800c24e --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,7 @@ +## 2024-05-24 - Avoid `.collect::>().join("")` for string concatenation in Rust +**Learning:** Found a pattern where multiple strings are aggregated using `.collect::>().join("")`, which introduces intermediate `Vec` allocations. +**Action:** Use `.collect::()` directly on an iterator of strings or string slices instead, which avoids the intermediate vector allocation when joining with an empty string. + +## 2024-05-24 - Use `to_lowercase().to_string()` over `to_lowercase().collect::()` +**Learning:** `char::to_lowercase()` returns an iterator (since a char can map to multiple chars), and using `.collect::()` on it has collection overhead. +**Action:** `char::to_lowercase()` implements `Display`, so prefer `.to_string()` over `.collect::()` to leverage its Display implementation directly for string conversion. diff --git a/xdk-lib/src/casing.rs b/xdk-lib/src/casing.rs index 6463487e..bd04c567 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(), } @@ -118,6 +114,6 @@ pub fn camel_case(value: &str) -> String { let mut chars = pascal.chars(); match chars.next() { None => String::new(), - Some(first) => first.to_lowercase().collect::() + chars.as_str(), + Some(first) => first.to_lowercase().to_string() + chars.as_str(), } }