Skip to content

Commit 2ac0aff

Browse files
committed
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: nodejs#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>
1 parent cf25324 commit 2ac0aff

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/path.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,9 @@ const win32 = {
788788
}
789789
}
790790
} else if (code === 47/*/*/ || code === 92/*\*/) {
791-
return path[0];
791+
// `path` contains just a path separator, exit early to avoid
792+
// unnecessary work
793+
return path;
792794
}
793795

794796
for (var i = len - 1; i >= offset; --i) {
@@ -1040,7 +1042,7 @@ const win32 = {
10401042
if (len === 3) {
10411043
// `path` contains just a drive root, exit early to avoid
10421044
// unnecessary work
1043-
ret.root = ret.dir = path.slice(0, 3);
1045+
ret.root = ret.dir = path;
10441046
return ret;
10451047
}
10461048
isAbsolute = true;
@@ -1049,15 +1051,15 @@ const win32 = {
10491051
} else {
10501052
// `path` contains just a drive root, exit early to avoid
10511053
// unnecessary work
1052-
ret.root = ret.dir = path.slice(0, 2);
1054+
ret.root = ret.dir = path;
10531055
return ret;
10541056
}
10551057
}
10561058
}
10571059
} else if (code === 47/*/*/ || code === 92/*\*/) {
10581060
// `path` contains just a path separator, exit early to avoid
10591061
// unnecessary work
1060-
ret.root = ret.dir = path[0];
1062+
ret.root = ret.dir = path;
10611063
return ret;
10621064
}
10631065

0 commit comments

Comments
 (0)