fs: avoid multiple conversions to string
nullCheck() implicitly converts the argument to string when checking the value, so this commit avoids any unnecessary additional (Buffer) conversions to string. PR-URL: https://github.com/nodejs/node/pull/10789 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
21b2440176
commit
34c9fc2e4e
16
lib/fs.js
16
lib/fs.js
@ -1503,21 +1503,21 @@ function encodeRealpathResult(result, options) {
|
|||||||
fs.realpathSync = function realpathSync(p, options) {
|
fs.realpathSync = function realpathSync(p, options) {
|
||||||
options = getOptions(options, {});
|
options = getOptions(options, {});
|
||||||
handleError((p = getPathFromURL(p)));
|
handleError((p = getPathFromURL(p)));
|
||||||
|
if (typeof p !== 'string')
|
||||||
|
p += '';
|
||||||
nullCheck(p);
|
nullCheck(p);
|
||||||
|
|
||||||
p = p.toString('utf8');
|
|
||||||
p = pathModule.resolve(p);
|
p = pathModule.resolve(p);
|
||||||
|
|
||||||
const seenLinks = {};
|
|
||||||
const knownHard = {};
|
|
||||||
const cache = options[internalFS.realpathCacheKey];
|
const cache = options[internalFS.realpathCacheKey];
|
||||||
const original = p;
|
|
||||||
|
|
||||||
const maybeCachedResult = cache && cache.get(p);
|
const maybeCachedResult = cache && cache.get(p);
|
||||||
if (maybeCachedResult) {
|
if (maybeCachedResult) {
|
||||||
return maybeCachedResult;
|
return maybeCachedResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const seenLinks = {};
|
||||||
|
const knownHard = {};
|
||||||
|
const original = p;
|
||||||
|
|
||||||
// current character position in p
|
// current character position in p
|
||||||
var pos;
|
var pos;
|
||||||
// the partial path so far, including a trailing slash if any
|
// the partial path so far, including a trailing slash if any
|
||||||
@ -1614,10 +1614,10 @@ fs.realpath = function realpath(p, options, callback) {
|
|||||||
options = getOptions(options, {});
|
options = getOptions(options, {});
|
||||||
if (handleError((p = getPathFromURL(p)), callback))
|
if (handleError((p = getPathFromURL(p)), callback))
|
||||||
return;
|
return;
|
||||||
|
if (typeof p !== 'string')
|
||||||
|
p += '';
|
||||||
if (!nullCheck(p, callback))
|
if (!nullCheck(p, callback))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p = p.toString('utf8');
|
|
||||||
p = pathModule.resolve(p);
|
p = pathModule.resolve(p);
|
||||||
|
|
||||||
const seenLinks = {};
|
const seenLinks = {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user