Skip to content

Commit

Permalink
path: remove unnecessary string copies
Browse files Browse the repository at this point in the history
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 <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>
  • Loading branch information
tniessen authored and addaleax committed Jul 27, 2017
1 parent 5057c7a commit 509039f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,9 @@ const win32 = {
}
}
} 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) {
Expand Down Expand Up @@ -1041,7 +1043,7 @@ const win32 = {
if (len === 3) {
// `path` contains just a drive root, exit early to avoid
// unnecessary work
ret.root = ret.dir = path.slice(0, 3);
ret.root = ret.dir = path;
return ret;
}
isAbsolute = true;
Expand All @@ -1050,15 +1052,15 @@ const win32 = {
} else {
// `path` contains just a drive root, exit early to avoid
// unnecessary work
ret.root = ret.dir = path.slice(0, 2);
ret.root = ret.dir = path;
return ret;
}
}
}
} else if (code === 47/*/*/ || code === 92/*\*/) {
// `path` contains just a path separator, exit early to avoid
// unnecessary work
ret.root = ret.dir = path[0];
ret.root = ret.dir = path;
return ret;
}

Expand Down

0 comments on commit 509039f

Please sign in to comment.