commit 4a14d59f404e5adc0028c26ae93c04eb837bdb5d
parent a618cd27aabd5fa20a43ac22d65244cd9e87090d
Author: William Casarin <jb55@jb55.com>
Date: Mon, 9 Feb 2026 11:32:27 -0800
dave: use push_str for token append to avoid O(n²) string growth
Replace `*msg = msg.clone() + &token` with `msg.push_str(&token)` to
append tokens in place rather than cloning the entire assistant message
on every token.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crates/notedeck_dave/src/lib.rs b/crates/notedeck_dave/src/lib.rs
@@ -263,7 +263,7 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
DaveApiResponse::Failed(err) => session.chat.push(Message::Error(err)),
DaveApiResponse::Token(token) => match session.chat.last_mut() {
- Some(Message::Assistant(msg)) => *msg = msg.clone() + &token,
+ Some(Message::Assistant(msg)) => msg.push_str(&token),
Some(_) => session.chat.push(Message::Assistant(token)),
None => {}
},