From 7953739f192b2c7a55c7f5ac667172a2e55c84e1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 24 Jun 2026 21:19:32 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Avoid=20intermediate=20allocations=20in=20casing=20operation?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What: Replaced `.collect::>().join("")` with `.collect::()` when concatenating pascal case words in `Casing::convert_words`, and replaced `.collect::()` with `.to_string()` on the first character in `camel_case`. Why: The previous implementation created unnecessary intermediate vector allocations before joining them into strings. Impact: Reduces memory allocations and CPU cycles during string casing conversions, which occur frequently during SDK generation. Measurement: Verified zero regressions via `make check` and `make test-generator`. Memory profiles will show fewer short-lived Vec allocations during the parsing and code generation phases. Co-authored-by: cloudesize67-cmd <237356855+cloudesize67-cmd@users.noreply.github.com> --- xdk-lib/src/casing.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/xdk-lib/src/casing.rs b/xdk-lib/src/casing.rs index 6463487e..f100cbf4 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(""), + // PERF: Direct collection into String avoids an intermediate Vec allocation + Casing::Pascal => words.iter().map(|w| pascal_case(w)).collect::(), Casing::Kebab => words.join("-").to_lowercase(), Casing::ScreamingSnake => words.join("_").to_uppercase(), } @@ -118,6 +115,7 @@ 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(), + // PERF: Leverage Display implementation via to_string() rather than iterator collection + Some(first) => first.to_lowercase().to_string() + chars.as_str(), } }