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 committed Jul 26, 2017
1 parent cf25324 commit 2ac0aff
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 @@ -1040,7 +1042,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 @@ -1049,15 +1051,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 2ac0aff

Please sign in to comment.