Skip to content

Commit 509039f

Browse files
tniessenaddaleax
authored andcommitted
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: #14438 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Khaidi Chu <[email protected]>
1 parent 5057c7a commit 509039f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/path.js

+6-4
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) {
@@ -1041,7 +1043,7 @@ const win32 = {
10411043
if (len === 3) {
10421044
// `path` contains just a drive root, exit early to avoid
10431045
// unnecessary work
1044-
ret.root = ret.dir = path.slice(0, 3);
1046+
ret.root = ret.dir = path;
10451047
return ret;
10461048
}
10471049
isAbsolute = true;
@@ -1050,15 +1052,15 @@ const win32 = {
10501052
} else {
10511053
// `path` contains just a drive root, exit early to avoid
10521054
// unnecessary work
1053-
ret.root = ret.dir = path.slice(0, 2);
1055+
ret.root = ret.dir = path;
10541056
return ret;
10551057
}
10561058
}
10571059
}
10581060
} else if (code === 47/*/*/ || code === 92/*\*/) {
10591061
// `path` contains just a path separator, exit early to avoid
10601062
// unnecessary work
1061-
ret.root = ret.dir = path[0];
1063+
ret.root = ret.dir = path;
10621064
return ret;
10631065
}
10641066

0 commit comments

Comments
 (0)