Skip to content

Commit b77afc0

Browse files
committed
path: refactor path joining logic for clarity and performance
1 parent b6cfba7 commit b77afc0

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/path.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -506,21 +506,20 @@ const win32 = {
506506
if (args.length === 0)
507507
return '.';
508508

509-
let joined;
510-
let firstPart;
509+
const path = [];
511510
for (let i = 0; i < args.length; ++i) {
512511
const arg = args[i];
513512
validateString(arg, 'path');
514513
if (arg.length > 0) {
515-
if (joined === undefined)
516-
joined = firstPart = arg;
517-
else
518-
joined += `\\${arg}`;
514+
path.push(arg);
519515
}
520516
}
521517

522-
if (joined === undefined)
518+
if (path.length === 0)
523519
return '.';
520+
521+
const firstPart = path[0];
522+
let joined = ArrayPrototypeJoin(path, '\\');
524523

525524
// Make sure that the joined path doesn't start with two slashes, because
526525
// normalize() will mistake it for a UNC path then.

0 commit comments

Comments
 (0)