Skip to content

Commit

Permalink
Micro-optimize PATH.basename. NFC (emscripten-core#23198)
Browse files Browse the repository at this point in the history
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%)                                 
```
  • Loading branch information
sbc100 authored Dec 18, 2024
1 parent 9d15e24 commit dea1bf9
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 26 deletions.
11 changes: 3 additions & 8 deletions src/library_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8507
8482
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20871
20818
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8491
8466
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20839
20786
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9537
9516
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24716
24663
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8467
8443
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20765
20711
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8467
8443
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20765
20711
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_lto.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8406
8389
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_lto.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20455
20402
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9541
9523
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24716
24663
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8507
8482
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20871
20818
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_js_fs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7646
7621
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_js_fs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18784
18731

0 comments on commit dea1bf9

Please sign in to comment.