From 21b24401768aa111142522fd56a49f8de805fd74 Mon Sep 17 00:00:00 2001 From: Brian White Date: Fri, 13 Jan 2017 05:04:18 -0500 Subject: [PATCH] fs: avoid recompilation of closure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: /~https://github.com/nodejs/node/pull/10789 Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso Reviewed-By: Michael Dawson Reviewed-By: Matteo Collina Reviewed-By: Benjamin Gruenbaum --- lib/fs.js | 86 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 929f7bcaa6b30b..eab8d942e183f0 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1527,21 +1527,16 @@ fs.realpathSync = function realpathSync(p, options) { // the partial path scanned in the previous round, with slash var previous; - start(); + // Skip over roots + var m = splitRootRe.exec(p); + pos = m[0].length; + current = m[0]; + base = m[0]; - function start() { - // Skip over roots - 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.lstatSync(base); - knownHard[base] = true; - } + // 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 @@ -1595,7 +1590,18 @@ fs.realpathSync = function realpathSync(p, options) { // resolve the link, then start over 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); @@ -1626,26 +1632,21 @@ fs.realpath = function realpath(p, options, callback) { // the partial path scanned in the previous round, with slash var previous; - start(); - - function start() { - // Skip over roots - var m = splitRootRe.exec(p); - pos = m[0].length; - current = m[0]; - base = m[0]; - previous = ''; + 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); - } + // 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); } // 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) { // resolve the link, then start over 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); + } } };