From 3ddf18441336983f308c7c56edc7c2a8edf7aebd Mon Sep 17 00:00:00 2001 From: skylar taylor-barrick Date: Mon, 19 Oct 2026 00:21:58 +0200 Subject: [PATCH] perf(engine): return an unedited snapshot's source without copying it (#3276) --- crates/engine/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index c1b00c8ec7..78a3d885ba 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -4116,21 +4116,20 @@ impl Session { let rewrite = editor.cos.full_save_required() || editor.cos.encryption_changed() || editor.cos.revisions().is_empty(); guard(|| { if on_saved || rewrite { - return write_incremental(&editor.cos, &opts); + return write_incremental(&editor.cos, &opts).map(Arc::new); } let mut base = pdfcraft_cos::Document::open_with_password(editor.saved.clone(), editor.saved_keys.reopen.as_deref())?; if base.overlay_changes_from(&editor.cos)? { - write_incremental(&base, &opts) + write_incremental(&base, &opts).map(Arc::new) } else if !editor.cos.is_modified() { - Ok(editor.cos.bytes().to_vec()) + Ok(editor.cos.bytes().clone()) } else { // Undo restored security from before the last save: append the snapshot to its // own source, which it hasn't changed security against. - write_incremental(&editor.cos, &opts) + write_incremental(&editor.cos, &opts).map(Arc::new) } }) .map_err(EditError::Write)? - .map(Arc::new) .map_err(|e| EditError::Write(e.to_string())) }