Skip to content

Commit 658c31d

Browse files
wlgh1553richardlau
authored andcommitted
path: refactor path joining logic for clarity and performance
PR-URL: #59781 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 079a68d commit 658c31d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/path.js

Lines 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)