diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-14 21:26:24 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-14 21:26:24 -0800 |
commit | 4f03b02970575775eefa6856b8d04be9e5a11a8b (patch) | |
tree | f32ebafd0ec4c522414f53ee0fa28749f7bf9aba /tools | |
parent | 28a19fedfed99cb56295234cb875c1f13811d114 (diff) |
vaccum per function in js optimizer
Diffstat (limited to 'tools')
-rw-r--r-- | tools/js-optimizer.js | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 765b00dc..9e400518 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -795,27 +795,27 @@ function vacuum(ast) { if (node[0] == 'block' && (!node[1] || (typeof node[1] != 'object') || node[1].length == 0 || (node[1].length == 1 && isEmpty(node[1])))) return true; return false; } - var more = true; - while (more) { - more = false; - function simplifyList(node, i) { - var changed = false; - var pre = node[i].length; - node[i] = node[i].filter(function(node) { return !isEmpty(node) }); - if (node[i].length < pre) changed = true; - // Also, seek blocks with single items we can simplify - node[i] = node[i].map(function(subNode) { - if (subNode[0] == 'block' && typeof subNode[1] == 'object' && subNode[1].length == 1 && subNode[1][0][0] == 'if') { - return subNode[1][0]; + traverseGeneratedFunctions(ast, function(node) { + var more = true; + while (more) { + more = false; + function simplifyList(node, i) { + var changed = false; + var pre = node[i].length; + node[i] = node[i].filter(function(node) { return !isEmpty(node) }); + if (node[i].length < pre) changed = true; + // Also, seek blocks with single items we can simplify + node[i] = node[i].map(function(subNode) { + if (subNode[0] == 'block' && typeof subNode[1] == 'object' && subNode[1].length == 1 && subNode[1][0][0] == 'if') { + return subNode[1][0]; + } + return subNode; + }); + if (changed) { + more = true; + return node; } - return subNode; - }); - if (changed) { - more = true; - return node; } - } - traverseGeneratedFunctions(ast, function(node) { simplifyNotComps(node); traverse(node, function(node, type) { var ret; @@ -879,8 +879,8 @@ function vacuum(ast) { } break; } }); - }); - } + } + }); } function getStatements(node) { @@ -998,7 +998,7 @@ function hoistMultiples(ast) { if (node[0] == 'block' && node[1].length == 1) node = node[1][0]; return node; } - vacuum([0, [node]]); + vacuum(node); traverse(node, function(node, type) { var statements = getStatements(node); if (!statements) return; |