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
This commit is contained in:
Charlie Marsh
2026-11-23 22:40:20 +00:00
committed by copyberry
parent c0a9009b7b
commit 93752dd4d5
+5 -5
View File
@@ -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<u8>,
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,
)