mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
path: refactor path joining logic for clarity and performance
PR-URL: https://github.com/nodejs/node/pull/59781 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
9d1c9c789b
commit
26607a650e
14
lib/path.js
14
lib/path.js
|
|
@ -24,6 +24,7 @@
|
|||
const {
|
||||
ArrayPrototypeIncludes,
|
||||
ArrayPrototypeJoin,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypeSlice,
|
||||
FunctionPrototypeBind,
|
||||
StringPrototypeCharCodeAt,
|
||||
|
|
@ -506,22 +507,21 @@ const win32 = {
|
|||
if (args.length === 0)
|
||||
return '.';
|
||||
|
||||
let joined;
|
||||
let firstPart;
|
||||
const path = [];
|
||||
for (let i = 0; i < args.length; ++i) {
|
||||
const arg = args[i];
|
||||
validateString(arg, 'path');
|
||||
if (arg.length > 0) {
|
||||
if (joined === undefined)
|
||||
joined = firstPart = arg;
|
||||
else
|
||||
joined += `\\${arg}`;
|
||||
ArrayPrototypePush(path, arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (joined === undefined)
|
||||
if (path.length === 0)
|
||||
return '.';
|
||||
|
||||
const firstPart = path[0];
|
||||
let joined = ArrayPrototypeJoin(path, '\\');
|
||||
|
||||
// Make sure that the joined path doesn't start with two slashes, because
|
||||
// normalize() will mistake it for a UNC path then.
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user