From 77a00ce1fb4ae2523e22b9b84ae09a0200502e38 Mon Sep 17 00:00:00 2001 From: Leo K Date: Tue, 5 Oct 2021 22:38:27 +0200 Subject: chore: various op cleanup (#12329) --- runtime/ops/io.rs | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'runtime/ops/io.rs') diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index 82fe3605c..0687fc397 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -1,7 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::not_supported; -use deno_core::error::null_opbuf; use deno_core::error::resource_unavailable; use deno_core::error::AnyError; use deno_core::op_async; @@ -387,9 +386,8 @@ impl Resource for StdFileResource { fn op_read_sync( state: &mut OpState, rid: ResourceId, - buf: Option, + mut buf: ZeroCopyBuf, ) -> Result { - let mut buf = buf.ok_or_else(null_opbuf)?; StdFileResource::with(state, rid, move |r| match r { Ok(std_file) => std_file .read(&mut buf) @@ -402,22 +400,21 @@ fn op_read_sync( async fn op_read_async( state: Rc>, rid: ResourceId, - buf: Option, + mut buf: ZeroCopyBuf, ) -> Result { - let buf = &mut buf.ok_or_else(null_opbuf)?; let resource = state.borrow().resource_table.get_any(rid)?; let nread = if let Some(s) = resource.downcast_rc::() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::() { - s.read(buf).await? + s.read(&mut buf).await? } else if let Some(s) = resource.downcast_rc::() { - s.read(buf).await? + s.read(&mut buf).await? } else { return Err(not_supported()); }; @@ -427,9 +424,8 @@ async fn op_read_async( fn op_write_sync( state: &mut OpState, rid: ResourceId, - buf: Option, + buf: ZeroCopyBuf, ) -> Result { - let buf = buf.ok_or_else(null_opbuf)?; StdFileResource::with(state, rid, move |r| match r { Ok(std_file) => std_file .write(&buf) @@ -442,20 +438,19 @@ fn op_write_sync( async fn op_write_async( state: Rc>, rid: ResourceId, - buf: Option, + buf: ZeroCopyBuf, ) -> Result { - let buf = &buf.ok_or_else(null_opbuf)?; let resource = state.borrow().resource_table.get_any(rid)?; let nwritten = if let Some(s) = resource.downcast_rc::() { - s.write(buf).await? + s.write(&buf).await? } else if let Some(s) = resource.downcast_rc::() { - s.write(buf).await? + s.write(&buf).await? } else if let Some(s) = resource.downcast_rc::() { - s.write(buf).await? + s.write(&buf).await? } else if let Some(s) = resource.downcast_rc::() { - s.write(buf).await? + s.write(&buf).await? } else if let Some(s) = resource.downcast_rc::() { - s.write(buf).await? + s.write(&buf).await? } else { return Err(not_supported()); }; -- cgit v1.2.3