1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

perf(ext/io): remove a data copy from File write (#18601)

Removes a data copy from all async `File::write` operations.
This commit is contained in:
Luca Casonato 2023-04-05 23:13:01 +02:00 committed by Levente Kurusa
parent 4f5d637841
commit 67bf9692df

View file

@ -520,18 +520,22 @@ impl StdFileResource {
.await
}
async fn write(self: Rc<Self>, data: &[u8]) -> Result<usize, AnyError> {
let buf = data.to_owned();
async fn write(
self: Rc<Self>,
view: BufView,
) -> Result<deno_core::WriteOutcome, AnyError> {
self
.with_inner_blocking_task(move |inner| inner.write_and_maybe_flush(&buf))
.with_inner_blocking_task(move |inner| {
let nwritten = inner.write_and_maybe_flush(&view)?;
Ok(deno_core::WriteOutcome::Partial { nwritten, view })
})
.await
}
async fn write_all(self: Rc<Self>, data: &[u8]) -> Result<(), AnyError> {
let buf = data.to_owned();
async fn write_all(self: Rc<Self>, view: BufView) -> Result<(), AnyError> {
self
.with_inner_blocking_task(move |inner| {
inner.write_all_and_maybe_flush(&buf)
inner.write_all_and_maybe_flush(&view)
})
.await
}
@ -644,7 +648,15 @@ impl Resource for StdFileResource {
Box::pin(self.read_byob(buf))
}
deno_core::impl_writable!(with_all);
fn write(
self: Rc<Self>,
view: deno_core::BufView,
) -> AsyncResult<deno_core::WriteOutcome> {
Box::pin(self.write(view))
}
fn write_all(self: Rc<Self>, view: deno_core::BufView) -> AsyncResult<()> {
Box::pin(self.write_all(view))
}
#[cfg(unix)]
fn backing_fd(self: Rc<Self>) -> Option<std::os::unix::prelude::RawFd> {