Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 2024-05-24 - Avoid `.collect::<Vec<_>>().join("")` for string concatenation in Rust
**Learning:** Found a pattern where multiple strings are aggregated using `.collect::<Vec<_>>().join("")`, which introduces intermediate `Vec` allocations.
**Action:** Use `.collect::<String>()` 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::<String>()`
**Learning:** `char::to_lowercase()` returns an iterator (since a char can map to multiple chars), and using `.collect::<String>()` on it has collection overhead.
**Action:** `char::to_lowercase()` implements `Display`, so prefer `.to_string()` over `.collect::<String>()` to leverage its Display implementation directly for string conversion.
8 changes: 2 additions & 6 deletions xdk-lib/src/casing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ impl Casing {
result
}
}
Casing::Pascal => words
.iter()
.map(|w| pascal_case(w))
.collect::<Vec<_>>()
.join(""),
Casing::Pascal => words.iter().map(|w| pascal_case(w)).collect::<String>(),
Casing::Kebab => words.join("-").to_lowercase(),
Casing::ScreamingSnake => words.join("_").to_uppercase(),
}
Expand Down Expand Up @@ -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::<String>() + chars.as_str(),
Some(first) => first.to_lowercase().to_string() + chars.as_str(),
}
}
Loading