diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-12-26 18:30:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 02:30:26 +0100 |
commit | 0efe438f7c191d8504355e03b27fe7e3055c9387 (patch) | |
tree | b96fe9a897eb6941c87a95a04520662d26c02fbe /ext/fs/30_fs.js | |
parent | e33c5eb704c22fad69876e87d9b852a4e5072a7a (diff) |
perf: remove opAsync (#21690)
`opAsync` requires a lookup by name on each async call. This is a
mechanical translation of all opAsync calls to ensureFastOps.
The `opAsync` API on Deno.core will be removed at a later time.
Diffstat (limited to 'ext/fs/30_fs.js')
-rw-r--r-- | ext/fs/30_fs.js | 90 |
1 files changed, 50 insertions, 40 deletions
diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index 29c6c4aac..a43a5297c 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -8,7 +8,32 @@ const { op_fs_truncate_async, op_fs_link_async, op_fs_flock_async, -} = Deno.core.ensureFastOps(); + op_fs_chown_async, + op_fs_copy_file_async, + op_fs_fdatasync_async, + op_fs_fstat_async, + op_fs_fsync_async, + op_fs_funlock_async, + op_fs_futime_async, + op_fs_lstat_async, + op_fs_make_temp_dir_async, + op_fs_make_temp_file_async, + op_fs_mkdir_async, + op_fs_open_async, + op_fs_read_dir_async, + op_fs_read_file_async, + op_fs_read_file_text_async, + op_fs_read_link_async, + op_fs_realpath_async, + op_fs_remove_async, + op_fs_rename_async, + op_fs_seek_async, + op_fs_stat_async, + op_fs_symlink_async, + op_fs_utime_async, + op_fs_write_file_async, +} = core.ensureFastOps(); + const { ArrayPrototypeFilter, Date, @@ -56,8 +81,7 @@ async function chown( uid, gid, ) { - await core.opAsync( - "op_fs_chown_async", + await op_fs_chown_async( pathFromURL(path), uid, gid, @@ -78,8 +102,7 @@ async function copyFile( fromPath, toPath, ) { - await core.opAsync( - "op_fs_copy_file_async", + await op_fs_copy_file_async( pathFromURL(fromPath), pathFromURL(toPath), ); @@ -102,8 +125,7 @@ function makeTempDirSync(options = {}) { } function makeTempDir(options = {}) { - return core.opAsync( - "op_fs_make_temp_dir_async", + return op_fs_make_temp_dir_async( options.dir, options.prefix, options.suffix, @@ -119,8 +141,7 @@ function makeTempFileSync(options = {}) { } function makeTempFile(options = {}) { - return core.opAsync( - "op_fs_make_temp_file_async", + return op_fs_make_temp_file_async( options.dir, options.prefix, options.suffix, @@ -136,8 +157,7 @@ function mkdirSync(path, options) { } async function mkdir(path, options) { - await core.opAsync( - "op_fs_mkdir_async", + await op_fs_mkdir_async( pathFromURL(path), options?.recursive ?? false, options?.mode, @@ -151,8 +171,7 @@ function readDirSync(path) { } function readDir(path) { - const array = core.opAsync( - "op_fs_read_dir_async", + const array = op_fs_read_dir_async( pathFromURL(path), ); return { @@ -170,7 +189,7 @@ function readLinkSync(path) { } function readLink(path) { - return core.opAsync("op_fs_read_link_async", pathFromURL(path)); + return op_fs_read_link_async(pathFromURL(path)); } function realPathSync(path) { @@ -178,7 +197,7 @@ function realPathSync(path) { } function realPath(path) { - return core.opAsync("op_fs_realpath_async", pathFromURL(path)); + return op_fs_realpath_async(pathFromURL(path)); } function removeSync( @@ -195,8 +214,7 @@ async function remove( path, options = {}, ) { - await core.opAsync( - "op_fs_remove_async", + await op_fs_remove_async( pathFromURL(path), !!options.recursive, ); @@ -210,8 +228,7 @@ function renameSync(oldpath, newpath) { } async function rename(oldpath, newpath) { - await core.opAsync( - "op_fs_rename_async", + await op_fs_rename_async( pathFromURL(oldpath), pathFromURL(newpath), ); @@ -340,11 +357,11 @@ function fstatSync(rid) { } async function fstat(rid) { - return parseFileInfo(await core.opAsync("op_fs_fstat_async", rid)); + return parseFileInfo(await op_fs_fstat_async(rid)); } async function lstat(path) { - const res = await core.opAsync("op_fs_lstat_async", pathFromURL(path)); + const res = await op_fs_lstat_async(pathFromURL(path)); return parseFileInfo(res); } @@ -354,7 +371,7 @@ function lstatSync(path) { } async function stat(path) { - const res = await core.opAsync("op_fs_stat_async", pathFromURL(path)); + const res = await op_fs_stat_async(pathFromURL(path)); return parseFileInfo(res); } @@ -436,8 +453,7 @@ async function futime( ) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); - await core.opAsync( - "op_fs_futime_async", + await op_fs_futime_async( rid, atimeSec, atimeNsec, @@ -469,8 +485,7 @@ async function utime( ) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); - await core.opAsync( - "op_fs_utime_async", + await op_fs_utime_async( pathFromURL(path), atimeSec, atimeNsec, @@ -496,8 +511,7 @@ async function symlink( newpath, options, ) { - await core.opAsync( - "op_fs_symlink_async", + await op_fs_symlink_async( pathFromURL(oldpath), pathFromURL(newpath), options?.type, @@ -509,7 +523,7 @@ function fdatasyncSync(rid) { } async function fdatasync(rid) { - await core.opAsync("op_fs_fdatasync_async", rid); + await op_fs_fdatasync_async(rid); } function fsyncSync(rid) { @@ -517,7 +531,7 @@ function fsyncSync(rid) { } async function fsync(rid) { - await core.opAsync("op_fs_fsync_async", rid); + await op_fs_fsync_async(rid); } function flockSync(rid, exclusive) { @@ -533,7 +547,7 @@ function funlockSync(rid) { } async function funlock(rid) { - await core.opAsync("op_fs_funlock_async", rid); + await op_fs_funlock_async(rid); } function seekSync( @@ -549,7 +563,7 @@ function seek( offset, whence, ) { - return core.opAsync("op_fs_seek_async", rid, offset, whence); + return op_fs_seek_async(rid, offset, whence); } function openSync( @@ -570,8 +584,7 @@ async function open( options, ) { if (options) checkOpenOptions(options); - const rid = await core.opAsync( - "op_fs_open_async", + const rid = await op_fs_open_async( pathFromURL(path), options, ); @@ -716,8 +729,7 @@ async function readFile(path, options) { } try { - const read = await core.opAsync( - "op_fs_read_file_async", + const read = await op_fs_read_file_async( pathFromURL(path), cancelRid, ); @@ -747,8 +759,7 @@ async function readTextFile(path, options) { } try { - const read = await core.opAsync( - "op_fs_read_file_text_async", + const read = await op_fs_read_file_text_async( pathFromURL(path), cancelRid, ); @@ -805,8 +816,7 @@ async function writeFile( signal: options.signal, }); } else { - await core.opAsync( - "op_fs_write_file_async", + await op_fs_write_file_async( pathFromURL(path), options.mode, options.append ?? false, |