You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit addebef
Browse filesBrowse the repository at this point in the historyBrowse files
Refactor push_str(&format!(...)) to use write! in canvas module
This commit optimizes string concatenation in the `canvas.rs` module by using `std::fmt::Write` and the `write!` macro instead of `push_str(&format!(...))`. This eliminates temporary `String` allocations inside rendering loops, reducing memory overhead and improving performance for complex canvas operations. Explanatory comments were added, and the learning was appended to the Bolt journal.
Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
Copy file name to clipboardExpand all lines: .jules/bolt.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,3 +11,6 @@
11
11
## 2024-06-25 - Suboptimal Line Search in LSP
12
12
**Learning:** Using `chars().nth()` with a byte offset (such as one returned by `.find()`) inside a loop over a string creates an O(N) penalty and may result in an incorrect character lookup if multi-byte unicode characters are present.
13
13
**Action:** Use string slicing with the byte index to create a subset string slice, and call `.chars().next_back()` or `.chars().next()` on it for an O(1) and UTF-8 safe boundary lookup.
14
+
## 2024-05-24 - Avoid `push_str(&format!(...))` in loops
15
+
**Learning:** Using `push_str(&format!(...))` inside loops creates unnecessary temporary String allocations because `format!` allocates a new `String` which is then appended and immediately dropped.
16
+
**Action:** Use `std::fmt::Write` and the `write!` macro directly onto the target string buffer instead.
# I will append the learning at the end if it doesn't exist, but since it currently only contains my previous write, I need to look at git history to restore it.
0 commit comments