path: remove unnecessary string copies
As the length of `path` is known at this point, there is no point in making an exact copy using `slice`. PR-URL: https://github.com/nodejs/node/pull/14438 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe>
This commit is contained in:
parent
cf25324476
commit
2ac0aff283
10
lib/path.js
10
lib/path.js
@ -788,7 +788,9 @@ const win32 = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (code === 47/*/*/ || code === 92/*\*/) {
|
} else if (code === 47/*/*/ || code === 92/*\*/) {
|
||||||
return path[0];
|
// `path` contains just a path separator, exit early to avoid
|
||||||
|
// unnecessary work
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = len - 1; i >= offset; --i) {
|
for (var i = len - 1; i >= offset; --i) {
|
||||||
@ -1040,7 +1042,7 @@ const win32 = {
|
|||||||
if (len === 3) {
|
if (len === 3) {
|
||||||
// `path` contains just a drive root, exit early to avoid
|
// `path` contains just a drive root, exit early to avoid
|
||||||
// unnecessary work
|
// unnecessary work
|
||||||
ret.root = ret.dir = path.slice(0, 3);
|
ret.root = ret.dir = path;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
isAbsolute = true;
|
isAbsolute = true;
|
||||||
@ -1049,7 +1051,7 @@ const win32 = {
|
|||||||
} else {
|
} else {
|
||||||
// `path` contains just a drive root, exit early to avoid
|
// `path` contains just a drive root, exit early to avoid
|
||||||
// unnecessary work
|
// unnecessary work
|
||||||
ret.root = ret.dir = path.slice(0, 2);
|
ret.root = ret.dir = path;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1057,7 +1059,7 @@ const win32 = {
|
|||||||
} else if (code === 47/*/*/ || code === 92/*\*/) {
|
} else if (code === 47/*/*/ || code === 92/*\*/) {
|
||||||
// `path` contains just a path separator, exit early to avoid
|
// `path` contains just a path separator, exit early to avoid
|
||||||
// unnecessary work
|
// unnecessary work
|
||||||
ret.root = ret.dir = path[0];
|
ret.root = ret.dir = path;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user