From dea1bf91f9b5b21cb76d6ddd12bcd54cd99e9c3f Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 18 Dec 2024 12:02:47 -0800 Subject: [PATCH] Micro-optimize PATH.basename. NFC (#23198) The following (18) test expectation files were updated by running the tests with `--rebaseline`: ``` other/codesize/test_codesize_cxx_ctors1.gzsize: 8507 => 8482 [-25 bytes / -0.29%] other/codesize/test_codesize_cxx_ctors1.jssize: 20871 => 20818 [-53 bytes / -0.25%] other/codesize/test_codesize_cxx_ctors2.gzsize: 8491 => 8466 [-25 bytes / -0.29%] other/codesize/test_codesize_cxx_ctors2.jssize: 20839 => 20786 [-53 bytes / -0.25%] other/codesize/test_codesize_cxx_except.gzsize: 9537 => 9516 [-21 bytes / -0.22%] other/codesize/test_codesize_cxx_except.jssize: 24716 => 24663 [-53 bytes / -0.21%] other/codesize/test_codesize_cxx_except_wasm.gzsize: 8467 => 8443 [-24 bytes / -0.28%] other/codesize/test_codesize_cxx_except_wasm.jssize: 20765 => 20711 [-54 bytes / -0.26%] other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize: 8467 => 8443 [-24 bytes / -0.28%] other/codesize/test_codesize_cxx_except_wasm_exnref.jssize: 20765 => 20711 [-54 bytes / -0.26%] other/codesize/test_codesize_cxx_lto.gzsize: 8406 => 8389 [-17 bytes / -0.20%] other/codesize/test_codesize_cxx_lto.jssize: 20455 => 20402 [-53 bytes / -0.26%] other/codesize/test_codesize_cxx_mangle.gzsize: 9541 => 9523 [-18 bytes / -0.19%] other/codesize/test_codesize_cxx_mangle.jssize: 24716 => 24663 [-53 bytes / -0.21%] other/codesize/test_codesize_cxx_noexcept.gzsize: 8507 => 8482 [-25 bytes / -0.29%] other/codesize/test_codesize_cxx_noexcept.jssize: 20871 => 20818 [-53 bytes / -0.25%] other/codesize/test_codesize_files_js_fs.gzsize: 7646 => 7621 [-25 bytes / -0.33%] other/codesize/test_codesize_files_js_fs.jssize: 18784 => 18731 [-53 bytes / -0.28%] Average change: -0.26% (-0.33% - -0.19%) ``` --- src/library_path.js | 11 +++-------- test/other/codesize/test_codesize_cxx_ctors1.gzsize | 2 +- test/other/codesize/test_codesize_cxx_ctors1.jssize | 2 +- test/other/codesize/test_codesize_cxx_ctors2.gzsize | 2 +- test/other/codesize/test_codesize_cxx_ctors2.jssize | 2 +- test/other/codesize/test_codesize_cxx_except.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except.jssize | 2 +- .../codesize/test_codesize_cxx_except_wasm.gzsize | 2 +- .../codesize/test_codesize_cxx_except_wasm.jssize | 2 +- .../test_codesize_cxx_except_wasm_exnref.gzsize | 2 +- .../test_codesize_cxx_except_wasm_exnref.jssize | 2 +- test/other/codesize/test_codesize_cxx_lto.gzsize | 2 +- test/other/codesize/test_codesize_cxx_lto.jssize | 2 +- test/other/codesize/test_codesize_cxx_mangle.gzsize | 2 +- test/other/codesize/test_codesize_cxx_mangle.jssize | 2 +- test/other/codesize/test_codesize_cxx_noexcept.gzsize | 2 +- test/other/codesize/test_codesize_cxx_noexcept.jssize | 2 +- test/other/codesize/test_codesize_files_js_fs.gzsize | 2 +- test/other/codesize/test_codesize_files_js_fs.jssize | 2 +- 19 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/library_path.js b/src/library_path.js index fd5fec3dc2c46..b1ff8364afb76 100644 --- a/src/library_path.js +++ b/src/library_path.js @@ -63,14 +63,9 @@ addToLibrary({ } return root + dir; }, - basename: (path) => { - // EMSCRIPTEN return '/' for '/', not an empty string - if (path === '/') return '/'; - path = path.replace(/\/+$/g, ""); - var lastSlash = path.lastIndexOf('/'); - if (lastSlash === -1) return path; - return path.substr(lastSlash+1); - }, + // This differs from node's path.basename in that it returns '/' for '/' + // rather than the empty string. + basename: (path) => path && path.match(/([^\/]+|\/)\/*$/)[1], join: (...paths) => PATH.normalize(paths.join('/')), join2: (l, r) => PATH.normalize(l + '/' + r), }, diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize index 46d2642cd5ff6..f8c4d739e8274 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize @@ -1 +1 @@ -8507 +8482 diff --git a/test/other/codesize/test_codesize_cxx_ctors1.jssize b/test/other/codesize/test_codesize_cxx_ctors1.jssize index 1ef4c19069463..3b3bc5532ae28 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors1.jssize @@ -1 +1 @@ -20871 +20818 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize index 7c325c18dbb27..6ed96170748c2 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize @@ -1 +1 @@ -8491 +8466 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.jssize b/test/other/codesize/test_codesize_cxx_ctors2.jssize index 27cf90d8e32cf..035c83c3d83de 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors2.jssize @@ -1 +1 @@ -20839 +20786 diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize index 527aa10c5664b..e0a4790acc2ab 100644 --- a/test/other/codesize/test_codesize_cxx_except.gzsize +++ b/test/other/codesize/test_codesize_cxx_except.gzsize @@ -1 +1 @@ -9537 +9516 diff --git a/test/other/codesize/test_codesize_cxx_except.jssize b/test/other/codesize/test_codesize_cxx_except.jssize index bef4f04c14b42..5540250d5313e 100644 --- a/test/other/codesize/test_codesize_cxx_except.jssize +++ b/test/other/codesize/test_codesize_cxx_except.jssize @@ -1 +1 @@ -24716 +24663 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize index e480013c31d9e..eb60637f84202 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize @@ -1 +1 @@ -8467 +8443 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.jssize b/test/other/codesize/test_codesize_cxx_except_wasm.jssize index f9b02e898e2f7..61b087013e3d6 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.jssize @@ -1 +1 @@ -20765 +20711 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize index e480013c31d9e..eb60637f84202 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize @@ -1 +1 @@ -8467 +8443 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize index f9b02e898e2f7..61b087013e3d6 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize @@ -1 +1 @@ -20765 +20711 diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize index 9fa65500fcae8..638eae8034903 100644 --- a/test/other/codesize/test_codesize_cxx_lto.gzsize +++ b/test/other/codesize/test_codesize_cxx_lto.gzsize @@ -1 +1 @@ -8406 +8389 diff --git a/test/other/codesize/test_codesize_cxx_lto.jssize b/test/other/codesize/test_codesize_cxx_lto.jssize index 6b82b8bab281e..6b1a29e39cd0b 100644 --- a/test/other/codesize/test_codesize_cxx_lto.jssize +++ b/test/other/codesize/test_codesize_cxx_lto.jssize @@ -1 +1 @@ -20455 +20402 diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize index e237f91b5925d..644357aa4e240 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.gzsize +++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize @@ -1 +1 @@ -9541 +9523 diff --git a/test/other/codesize/test_codesize_cxx_mangle.jssize b/test/other/codesize/test_codesize_cxx_mangle.jssize index bef4f04c14b42..5540250d5313e 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.jssize +++ b/test/other/codesize/test_codesize_cxx_mangle.jssize @@ -1 +1 @@ -24716 +24663 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize index 46d2642cd5ff6..f8c4d739e8274 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize +++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize @@ -1 +1 @@ -8507 +8482 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.jssize b/test/other/codesize/test_codesize_cxx_noexcept.jssize index 1ef4c19069463..3b3bc5532ae28 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.jssize +++ b/test/other/codesize/test_codesize_cxx_noexcept.jssize @@ -1 +1 @@ -20871 +20818 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index d7b618a3dc7f6..7afd85884af0e 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7646 +7621 diff --git a/test/other/codesize/test_codesize_files_js_fs.jssize b/test/other/codesize/test_codesize_files_js_fs.jssize index ffdc6a7d818a0..9aa6c5e6556ea 100644 --- a/test/other/codesize/test_codesize_files_js_fs.jssize +++ b/test/other/codesize/test_codesize_files_js_fs.jssize @@ -1 +1 @@ -18784 +18731