Skip to content

Commit 21b2440

Browse files
committed
fs: avoid recompilation of closure
PR-URL: #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]>
1 parent 190dc69 commit 21b2440

File tree

1 file changed

+51
-35
lines changed

1 file changed

+51
-35
lines changed

lib/fs.js

+51-35
Original file line numberDiff line numberDiff line change
@@ -1527,21 +1527,16 @@ fs.realpathSync = function realpathSync(p, options) {
15271527
// the partial path scanned in the previous round, with slash
15281528
var previous;
15291529

1530-
start();
1530+
// Skip over roots
1531+
var m = splitRootRe.exec(p);
1532+
pos = m[0].length;
1533+
current = m[0];
1534+
base = m[0];
15311535

1532-
function start() {
1533-
// Skip over roots
1534-
var m = splitRootRe.exec(p);
1535-
pos = m[0].length;
1536-
current = m[0];
1537-
base = m[0];
1538-
previous = '';
1539-
1540-
// On windows, check that the root exists. On unix there is no need.
1541-
if (isWindows && !knownHard[base]) {
1542-
fs.lstatSync(base);
1543-
knownHard[base] = true;
1544-
}
1536+
// On windows, check that the root exists. On unix there is no need.
1537+
if (isWindows && !knownHard[base]) {
1538+
fs.lstatSync(base);
1539+
knownHard[base] = true;
15451540
}
15461541

15471542
// walk down the path, swapping out linked pathparts for their real
@@ -1595,7 +1590,18 @@ fs.realpathSync = function realpathSync(p, options) {
15951590

15961591
// resolve the link, then start over
15971592
p = pathModule.resolve(resolvedLink, p.slice(pos));
1598-
start();
1593+
1594+
// Skip over roots
1595+
m = splitRootRe.exec(p);
1596+
pos = m[0].length;
1597+
current = m[0];
1598+
base = m[0];
1599+
1600+
// On windows, check that the root exists. On unix there is no need.
1601+
if (isWindows && !knownHard[base]) {
1602+
fs.lstatSync(base);
1603+
knownHard[base] = true;
1604+
}
15991605
}
16001606

16011607
if (cache) cache.set(original, p);
@@ -1626,26 +1632,21 @@ fs.realpath = function realpath(p, options, callback) {
16261632
// the partial path scanned in the previous round, with slash
16271633
var previous;
16281634

1629-
start();
1630-
1631-
function start() {
1632-
// Skip over roots
1633-
var m = splitRootRe.exec(p);
1634-
pos = m[0].length;
1635-
current = m[0];
1636-
base = m[0];
1637-
previous = '';
1635+
var m = splitRootRe.exec(p);
1636+
pos = m[0].length;
1637+
current = m[0];
1638+
base = m[0];
1639+
previous = '';
16381640

1639-
// On windows, check that the root exists. On unix there is no need.
1640-
if (isWindows && !knownHard[base]) {
1641-
fs.lstat(base, function(err) {
1642-
if (err) return callback(err);
1643-
knownHard[base] = true;
1644-
LOOP();
1645-
});
1646-
} else {
1647-
process.nextTick(LOOP);
1648-
}
1641+
// On windows, check that the root exists. On unix there is no need.
1642+
if (isWindows && !knownHard[base]) {
1643+
fs.lstat(base, function(err) {
1644+
if (err) return callback(err);
1645+
knownHard[base] = true;
1646+
LOOP();
1647+
});
1648+
} else {
1649+
process.nextTick(LOOP);
16491650
}
16501651

16511652
// walk down the path, swapping out linked pathparts for their real
@@ -1711,7 +1712,22 @@ fs.realpath = function realpath(p, options, callback) {
17111712
function gotResolvedLink(resolvedLink) {
17121713
// resolve the link, then start over
17131714
p = pathModule.resolve(resolvedLink, p.slice(pos));
1714-
start();
1715+
var m = splitRootRe.exec(p);
1716+
pos = m[0].length;
1717+
current = m[0];
1718+
base = m[0];
1719+
previous = '';
1720+
1721+
// On windows, check that the root exists. On unix there is no need.
1722+
if (isWindows && !knownHard[base]) {
1723+
fs.lstat(base, function(err) {
1724+
if (err) return callback(err);
1725+
knownHard[base] = true;
1726+
LOOP();
1727+
});
1728+
} else {
1729+
process.nextTick(LOOP);
1730+
}
17151731
}
17161732
};
17171733

0 commit comments

Comments
 (0)