mirror of
https://github.com/storytold/lightcraft.git
synced 2026-12-02 02:46:10 -06:00
#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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user