From cee4ae0888ed389860c60c911f579fa31e6746fa Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 26 Jun 2026 21:23:58 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Optimize=20string=20and=20character=20collection=20in=20casi?= =?UTF-8?q?ng=20conversions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaced `.collect::>().join("")` with `.collect::()` when concatenating Pascal case words to avoid allocating an intermediate `Vec`. - Replaced `first.to_lowercase().collect::()` with `first.to_lowercase().to_string()` to avoid unnecessary iterator collection overhead when converting the first character to lower case. Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com> --- .jules/bolt.md | 3 +++ xdk-lib/src/casing.rs | 8 ++------ 2 files changed, 5 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..e8f9a0f1 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-06-26 - String Concatenation Optimization +**Learning:** In Rust, `.collect::>().join("")` allocates an intermediate vector on the heap just to hold strings before joining them. Similarly, chaining `.collect::()` when converting cases (like `.to_lowercase().collect::()`) creates an intermediate string buffer. +**Action:** When joining strings without a separator, directly collect into a String using `.collect::()`. When converting the casing of a single character, leverage its Display implementation directly with `.to_lowercase().to_string()` to avoid unnecessary intermediate heap allocations. 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(), } }