Skip to content

Commit f667215

Browse files
wlgh1553targos
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 15e547b commit f667215

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,
@@ -506,22 +507,21 @@ const win32 = {
506507
if (args.length === 0)
507508
return '.';
508509

509-
let joined;
510-
let firstPart;
510+
const path = [];
511511
for (let i = 0; i < args.length; ++i) {
512512
const arg = args[i];
513513
validateString(arg, 'path');
514514
if (arg.length > 0) {
515-
if (joined === undefined)
516-
joined = firstPart = arg;
517-
else
518-
joined += `\\${arg}`;
515+
ArrayPrototypePush(path, arg);
519516
}
520517
}
521518

522-
if (joined === undefined)
519+
if (path.length === 0)
523520
return '.';
524521

522+
const firstPart = path[0];
523+
let joined = ArrayPrototypeJoin(path, '\\');
524+
525525
// Make sure that the joined path doesn't start with two slashes, because
526526
// normalize() will mistake it for a UNC path then.
527527
//

0 commit comments

Comments
 (0)