Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 658c31d

Browse filesBrowse files
wlgh1553richardlau
authored andcommitted
path: refactor path joining logic for clarity and performance
PR-URL: #59781 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 079a68d commit 658c31d
Copy full SHA for 658c31d

File tree

Expand file treeCollapse file tree

1 file changed

+7
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-7
lines changed
Open diff view settings
Collapse file

‎lib/path.js‎

Copy file name to clipboardExpand all lines: lib/path.js
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
const {
2525
ArrayPrototypeIncludes,
2626
ArrayPrototypeJoin,
27+
ArrayPrototypePush,
2728
ArrayPrototypeSlice,
2829
FunctionPrototypeBind,
2930
StringPrototypeCharCodeAt,
@@ -521,22 +522,21 @@ const win32 = {
521522
if (args.length === 0)
522523
return '.';
523524

524-
let joined;
525-
let firstPart;
525+
const path = [];
526526
for (let i = 0; i < args.length; ++i) {
527527
const arg = args[i];
528528
validateString(arg, 'path');
529529
if (arg.length > 0) {
530-
if (joined === undefined)
531-
joined = firstPart = arg;
532-
else
533-
joined += `\\${arg}`;
530+
ArrayPrototypePush(path, arg);
534531
}
535532
}
536533

537-
if (joined === undefined)
534+
if (path.length === 0)
538535
return '.';
539536

537+
const firstPart = path[0];
538+
let joined = ArrayPrototypeJoin(path, '\\');
539+
540540
// Make sure that the joined path doesn't start with two slashes, because
541541
// normalize() will mistake it for a UNC path then.
542542
//

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.