Skip to content

Commit e82a914

Browse files
tniessenMylesBorins
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`. Backport-PR-URL: #14787 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 eefd322 commit e82a914

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
@@ -767,7 +767,9 @@ const win32 = {
767767
}
768768
}
769769
} else if (code === 47/*/*/ || code === 92/*\*/) {
770-
return path[0];
770+
// `path` contains just a path separator, exit early to avoid
771+
// unnecessary work
772+
return path;
771773
}
772774

773775
for (var i = len - 1; i >= offset; --i) {
@@ -1031,23 +1033,23 @@ const win32 = {
10311033
if (len === 3) {
10321034
// `path` contains just a drive root, exit early to avoid
10331035
// unnecessary work
1034-
ret.root = ret.dir = path.slice(0, 3);
1036+
ret.root = ret.dir = path;
10351037
return ret;
10361038
}
10371039
rootEnd = 3;
10381040
}
10391041
} else {
10401042
// `path` contains just a drive root, exit early to avoid
10411043
// unnecessary work
1042-
ret.root = ret.dir = path.slice(0, 2);
1044+
ret.root = ret.dir = path;
10431045
return ret;
10441046
}
10451047
}
10461048
}
10471049
} else if (code === 47/*/*/ || code === 92/*\*/) {
10481050
// `path` contains just a path separator, exit early to avoid
10491051
// unnecessary work
1050-
ret.root = ret.dir = path[0];
1052+
ret.root = ret.dir = path;
10511053
return ret;
10521054
}
10531055

0 commit comments

Comments
 (0)