Browse Source

fs: avoid recompilation of closure

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>
v6
Brian White 8 years ago
parent
commit
21b2440176
No known key found for this signature in database GPG Key ID: 606D7358F94DA209
  1. 86
      lib/fs.js

86
lib/fs.js

@ -1527,21 +1527,16 @@ fs.realpathSync = function realpathSync(p, options) {
// the partial path scanned in the previous round, with slash // the partial path scanned in the previous round, with slash
var previous; var previous;
start(); // Skip over roots
var m = splitRootRe.exec(p);
pos = m[0].length;
current = m[0];
base = m[0];
function start() { // On windows, check that the root exists. On unix there is no need.
// Skip over roots if (isWindows && !knownHard[base]) {
var m = splitRootRe.exec(p); fs.lstatSync(base);
pos = m[0].length; knownHard[base] = true;
current = m[0];
base = m[0];
previous = '';
// On windows, check that the root exists. On unix there is no need.
if (isWindows && !knownHard[base]) {
fs.lstatSync(base);
knownHard[base] = true;
}
} }
// walk down the path, swapping out linked pathparts for their real // walk down the path, swapping out linked pathparts for their real
@ -1595,7 +1590,18 @@ fs.realpathSync = function realpathSync(p, options) {
// resolve the link, then start over // resolve the link, then start over
p = pathModule.resolve(resolvedLink, p.slice(pos)); p = pathModule.resolve(resolvedLink, p.slice(pos));
start();
// Skip over roots
m = splitRootRe.exec(p);
pos = m[0].length;
current = m[0];
base = m[0];
// On windows, check that the root exists. On unix there is no need.
if (isWindows && !knownHard[base]) {
fs.lstatSync(base);
knownHard[base] = true;
}
} }
if (cache) cache.set(original, p); if (cache) cache.set(original, p);
@ -1626,26 +1632,21 @@ fs.realpath = function realpath(p, options, callback) {
// the partial path scanned in the previous round, with slash // the partial path scanned in the previous round, with slash
var previous; var previous;
start(); var m = splitRootRe.exec(p);
pos = m[0].length;
function start() { current = m[0];
// Skip over roots base = m[0];
var m = splitRootRe.exec(p); previous = '';
pos = m[0].length;
current = m[0];
base = m[0];
previous = '';
// On windows, check that the root exists. On unix there is no need. // On windows, check that the root exists. On unix there is no need.
if (isWindows && !knownHard[base]) { if (isWindows && !knownHard[base]) {
fs.lstat(base, function(err) { fs.lstat(base, function(err) {
if (err) return callback(err); if (err) return callback(err);
knownHard[base] = true; knownHard[base] = true;
LOOP(); LOOP();
}); });
} else { } else {
process.nextTick(LOOP); process.nextTick(LOOP);
}
} }
// walk down the path, swapping out linked pathparts for their real // walk down the path, swapping out linked pathparts for their real
@ -1711,7 +1712,22 @@ fs.realpath = function realpath(p, options, callback) {
function gotResolvedLink(resolvedLink) { function gotResolvedLink(resolvedLink) {
// resolve the link, then start over // resolve the link, then start over
p = pathModule.resolve(resolvedLink, p.slice(pos)); p = pathModule.resolve(resolvedLink, p.slice(pos));
start(); var m = splitRootRe.exec(p);
pos = m[0].length;
current = m[0];
base = m[0];
previous = '';
// On windows, check that the root exists. On unix there is no need.
if (isWindows && !knownHard[base]) {
fs.lstat(base, function(err) {
if (err) return callback(err);
knownHard[base] = true;
LOOP();
});
} else {
process.nextTick(LOOP);
}
} }
}; };

Loading…
Cancel
Save