Skip to content

Commit

Permalink
fs: avoid multiple conversions to string
Browse files Browse the repository at this point in the history
nullCheck() implicitly converts the argument to string when checking
the value, so this commit avoids any unnecessary additional (Buffer)
conversions to string.

PR-URL: nodejs#10789
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
mscdex authored and jungx098 committed Mar 21, 2017
1 parent 331155b commit ac26f24
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,21 +1503,21 @@ function encodeRealpathResult(result, options) {
fs.realpathSync = function realpathSync(p, options) {
options = getOptions(options, {});
handleError((p = getPathFromURL(p)));
if (typeof p !== 'string')
p += '';
nullCheck(p);

p = p.toString('utf8');
p = pathModule.resolve(p);

const seenLinks = {};
const knownHard = {};
const cache = options[internalFS.realpathCacheKey];
const original = p;

const maybeCachedResult = cache && cache.get(p);
if (maybeCachedResult) {
return maybeCachedResult;
}

const seenLinks = {};
const knownHard = {};
const original = p;

// current character position in p
var pos;
// the partial path so far, including a trailing slash if any
Expand Down Expand Up @@ -1614,10 +1614,10 @@ fs.realpath = function realpath(p, options, callback) {
options = getOptions(options, {});
if (handleError((p = getPathFromURL(p)), callback))
return;
if (typeof p !== 'string')
p += '';
if (!nullCheck(p, callback))
return;

p = p.toString('utf8');
p = pathModule.resolve(p);

const seenLinks = {};
Expand Down

0 comments on commit ac26f24

Please sign in to comment.