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`.

Backport-PR-URL: #14787
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 MylesBorins committed Aug 16, 2017
1 parent eefd322 commit e82a914
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 @@ -767,7 +767,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 @@ -1031,23 +1033,23 @@ 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;
}
rootEnd = 3;
}
} 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 e82a914

Please sign in to comment.