GeezerVison is showing github.com — path: refactor path joining logic for clarity and performance · nodejs/node@f667215
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/path.js +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
24 | 24 | const { |
25 | 25 | ArrayPrototypeIncludes, |
26 | 26 | ArrayPrototypeJoin, |
| 27 | + ArrayPrototypePush, |
27 | 28 | ArrayPrototypeSlice, |
28 | 29 | FunctionPrototypeBind, |
29 | 30 | StringPrototypeCharCodeAt, |
@@ -506,22 +507,21 @@ const win32 = { |
506 | 507 | if (args.length === 0) |
507 | 508 | return '.'; |
508 | 509 |
|
509 | | - let joined; |
510 | | - let firstPart; |
| 510 | + const path = []; |
511 | 511 | for (let i = 0; i < args.length; ++i) { |
512 | 512 | const arg = args[i]; |
513 | 513 | validateString(arg, 'path'); |
514 | 514 | if (arg.length > 0) { |
515 | | - if (joined === undefined) |
516 | | - joined = firstPart = arg; |
517 | | - else |
518 | | - joined += `\\${arg}`; |
| 515 | + ArrayPrototypePush(path, arg); |
519 | 516 | } |
520 | 517 | } |
521 | 518 |
|
522 | | - if (joined === undefined) |
| 519 | + if (path.length === 0) |
523 | 520 | return '.'; |
524 | 521 |
|
| 522 | + const firstPart = path[0]; |
| 523 | + let joined = ArrayPrototypeJoin(path, '\\'); |
| 524 | + |
525 | 525 | // Make sure that the joined path doesn't start with two slashes, because |
526 | 526 | // normalize() will mistake it for a UNC path then. |
527 | 527 | // |
|