diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-12-01 21:29:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-02 05:29:15 +0000 |
commit | 9b2b8df927ac23cfa99016a684179f2a3198ba2e (patch) | |
tree | 1d13b575bc7c4f7279b2ff3fdde175a7522d643a /runtime/ops/fs.rs | |
parent | 075854e5162c3d9f4fd7061d19acbe2c5855536e (diff) |
feat(ops): Fast zero copy string arguments (#16777)
Uses SeqOneByteString optimization to do zero-copy `&str` arguments in
fast calls.
- [x] Depends on https://github.com/denoland/rusty_v8/pull/1129
- [x] Depends on
https://chromium-review.googlesource.com/c/v8/v8/+/4036884
- [x] Disable in async ops
- [x] Make it work with owned `String` with an extra alloc in fast path.
- [x] Support `Cow<'_, str>`. Owned for slow case, Borrowed for fast
case
```rust
#[op]
fn op_string_len(s: &str) -> u32 {
str.len() as u32
}
```
Diffstat (limited to 'runtime/ops/fs.rs')
-rw-r--r-- | runtime/ops/fs.rs | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs index ebd24ebe0..8d719393f 100644 --- a/runtime/ops/fs.rs +++ b/runtime/ops/fs.rs @@ -524,13 +524,13 @@ fn op_umask(state: &mut OpState, mask: Option<u32>) -> Result<u32, AnyError> { } #[op] -fn op_chdir(state: &mut OpState, directory: String) -> Result<(), AnyError> { +fn op_chdir(state: &mut OpState, directory: &str) -> Result<(), AnyError> { let d = PathBuf::from(&directory); state .borrow_mut::<Permissions>() .read .check(&d, Some("Deno.chdir()"))?; - set_current_dir(&d).map_err(|err| { + set_current_dir(d).map_err(|err| { Error::new(err.kind(), format!("{}, chdir '{}'", err, directory)) })?; Ok(()) @@ -603,10 +603,10 @@ async fn op_mkdir_async( #[op] fn op_chmod_sync( state: &mut OpState, - path: String, + path: &str, mode: u32, ) -> Result<(), AnyError> { - let path = Path::new(&path); + let path = Path::new(path); let mode = mode & 0o777; state @@ -661,11 +661,11 @@ fn raw_chmod(path: &Path, _raw_mode: u32) -> Result<(), AnyError> { #[op] fn op_chown_sync( state: &mut OpState, - path: String, + path: &str, #[cfg_attr(windows, allow(unused_variables))] uid: Option<u32>, #[cfg_attr(windows, allow(unused_variables))] gid: Option<u32>, ) -> Result<(), AnyError> { - let path = Path::new(&path).to_path_buf(); + let path = Path::new(path).to_path_buf(); state .borrow_mut::<Permissions>() .write @@ -734,10 +734,10 @@ async fn op_chown_async( #[op] fn op_remove_sync( state: &mut OpState, - path: String, + path: &str, recursive: bool, ) -> Result<(), AnyError> { - let path = PathBuf::from(&path); + let path = PathBuf::from(path); state .borrow_mut::<Permissions>() @@ -835,11 +835,11 @@ async fn op_remove_async( #[op] fn op_copy_file_sync( state: &mut OpState, - from: String, - to: String, + from: &str, + to: &str, ) -> Result<(), AnyError> { - let from_path = PathBuf::from(&from); - let to_path = PathBuf::from(&to); + let from_path = PathBuf::from(from); + let to_path = PathBuf::from(to); let permissions = state.borrow_mut::<Permissions>(); permissions @@ -1097,11 +1097,11 @@ pub struct StatArgs { #[op] fn op_stat_sync( state: &mut OpState, - path: String, + path: &str, lstat: bool, out_buf: &mut [u32], ) -> Result<(), AnyError> { - let path = PathBuf::from(&path); + let path = PathBuf::from(path); state .borrow_mut::<Permissions>() .read @@ -1313,11 +1313,11 @@ async fn op_read_dir_async( #[op] fn op_rename_sync( state: &mut OpState, - oldpath: String, - newpath: String, + oldpath: &str, + newpath: &str, ) -> Result<(), AnyError> { - let oldpath = PathBuf::from(&oldpath); - let newpath = PathBuf::from(&newpath); + let oldpath = PathBuf::from(oldpath); + let newpath = PathBuf::from(newpath); let permissions = state.borrow_mut::<Permissions>(); permissions @@ -1382,11 +1382,11 @@ async fn op_rename_async( #[op] fn op_link_sync( state: &mut OpState, - oldpath: String, - newpath: String, + oldpath: &str, + newpath: &str, ) -> Result<(), AnyError> { - let oldpath = PathBuf::from(&oldpath); - let newpath = PathBuf::from(&newpath); + let oldpath = PathBuf::from(oldpath); + let newpath = PathBuf::from(newpath); let permissions = state.borrow_mut::<Permissions>(); permissions.read.check(&oldpath, Some("Deno.linkSync()"))?; @@ -1449,12 +1449,12 @@ async fn op_link_async( #[op] fn op_symlink_sync( state: &mut OpState, - oldpath: String, - newpath: String, + oldpath: &str, + newpath: &str, _type: Option<String>, ) -> Result<(), AnyError> { - let oldpath = PathBuf::from(&oldpath); - let newpath = PathBuf::from(&newpath); + let oldpath = PathBuf::from(oldpath); + let newpath = PathBuf::from(newpath); state .borrow_mut::<Permissions>() @@ -1669,10 +1669,10 @@ async fn op_ftruncate_async( #[op] fn op_truncate_sync( state: &mut OpState, - path: String, + path: &str, len: u64, ) -> Result<(), AnyError> { - let path = PathBuf::from(&path); + let path = PathBuf::from(path); state .borrow_mut::<Permissions>() @@ -1949,13 +1949,13 @@ async fn op_futime_async( #[op] fn op_utime_sync( state: &mut OpState, - path: String, + path: &str, atime_secs: i64, atime_nanos: u32, mtime_secs: i64, mtime_nanos: u32, ) -> Result<(), AnyError> { - let path = PathBuf::from(&path); + let path = PathBuf::from(path); let atime = filetime::FileTime::from_unix_time(atime_secs, atime_nanos); let mtime = filetime::FileTime::from_unix_time(mtime_secs, mtime_nanos); |