From 93752dd4d556b3899618a893933ce379c57fc89d Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 23 Nov 2026 20:45:22 +0000 Subject: [PATCH] Avoid redundant buffer copies when applying patches (#63460) Borrow the contents of added and updated files. Allocate the byte vector required by the filesystem once for the initial write and again only if the write is retried after creating a missing parent directory. GitOrigin-RevId: b193f0c979aecc65b3b7b6307ba1c45a6898de16 --- codex-rs/apply-patch/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/codex-rs/apply-patch/src/lib.rs b/codex-rs/apply-patch/src/lib.rs index 315a6425d0..d72e8f2e9f 100644 --- a/codex-rs/apply-patch/src/lib.rs +++ b/codex-rs/apply-patch/src/lib.rs @@ -483,7 +483,7 @@ async fn apply_hunks_to_files( write_file_with_missing_parent_retry( fs, &path_uri, - contents.clone().into_bytes(), + contents.as_bytes(), follow_symlinks, sandbox, ) @@ -594,7 +594,7 @@ async fn apply_hunks_to_files( write_file_with_missing_parent_retry( fs, &dest_uri, - new_contents.clone().into_bytes(), + new_contents.as_bytes(), follow_symlinks, sandbox, ) @@ -765,14 +765,14 @@ async fn note_existing_path_delta_support( async fn write_file_with_missing_parent_retry( fs: &dyn ExecutorFileSystem, path: &PathUri, - contents: Vec, + contents: &[u8], follow_symlinks: bool, sandbox: Option<&FileSystemSandboxContext>, ) -> anyhow::Result<()> { match fs .write_file( path, - contents.clone(), + contents.to_vec(), WriteFileOptions { follow_symlinks }, sandbox, ) @@ -799,7 +799,7 @@ async fn write_file_with_missing_parent_retry( } fs.write_file( path, - contents, + contents.to_vec(), WriteFileOptions { follow_symlinks }, sandbox, )