#2270: an accepted photo's bytes are moved into the message, not cloned

Review follow-up (CodeRabbit): the clone doubled the memory a large photo takes for a moment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AbegtYaPuwqZ81pGfELsFK
This commit is contained in:
Claude
2026-10-22 11:54:28 +00:00
parent 2115f8eeb3
commit 7ffdb17c04
+8 -3
View File
@@ -219,14 +219,19 @@ mod bridge {
return;
}
let data = event.data();
let bytes = bytes(&data);
// moved, not cloned: an accepted photo can be hundreds of MB
let (bytes, oversize) = match bytes(&data) {
Some(Ok(b)) => (Some(b), None),
Some(Err(len)) => (None, Some(len)),
None => (None, None),
};
let raw = Raw {
kind: string(&data, "type"),
name: string(&data, "name"),
bytes: bytes.as_ref().and_then(|b| b.as_ref().ok().cloned()),
bytes,
id: string(&data, "id"),
params: string(&data, "params"),
oversize: bytes.and_then(Result::err),
oversize,
};
if let Some(m) = Incoming::parse(raw) {
incoming.borrow_mut().push(m);