Skip to content
Merged
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
4 changes: 1 addition & 3 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
## 2024-08-01 - Bytecode Disassembler String Allocation Optimization
**Learning:** Formatting directly into a string buffer inside a tight loop with `write!(buffer, ...)` avoids unnecessary string heap allocations compared to `buffer.push_str(&format!(...))`.
**Action:** Always prefer formatting directly into the target String buffer when concatenating strings in loops in performance-sensitive paths like debuggers or disassemblers.
## 2024-11-20 - [SQLite Query Mapping Optimization]
**Learning:** In dynamically typed environments, unconditionally casting database query results to strings (e.g., via `row.get::<_, String>`) before mapping them to internal types is highly inefficient and creates bugs. Direct iteration matching over native database memory representations (like `rusqlite::types::ValueRef`) preserves typing metadata and prevents unnecessary allocations.
**Action:** When extracting data from a database adapter layer to dynamic variants, use exact matching (e.g., `ValueRef::Integer`) and initialize the destination collections using `.with_capacity()` based on the column count.

17 changes: 12 additions & 5 deletions tools/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,11 +1291,18 @@ impl LanguageServer for Backend {
let start = range.start.line as usize;
let end = (range.end.line as usize).min(lines.len() - 1);

let mut selection = String::new();
for i in start..=end {
selection.push_str(lines[i]);
selection.push('\n');
}
let selection = if start <= end {
let slice = &lines[start..=end];
let capacity: usize = slice.iter().map(|l| l.len() + 1).sum();
let mut s = String::with_capacity(capacity);
for line in slice {
s.push_str(line);
s.push('\n');
}
s
} else {
String::new()
};

let formatted = self.format_source(&selection);
Ok(Some(vec![TextEdit {
Expand Down
Loading