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: nodejs#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]>
  • Loading branch information
tniessen committed Aug 14, 2017
1 parent 6fa5f35 commit f5a8586
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 f5a8586

Please sign in to comment.