diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-05-16 11:02:03 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-05-16 11:02:03 -0700 |
commit | b312ce10210b22db941c64502b87c032360a0f70 (patch) | |
tree | 7aeb604070c2a1c9f88c622eda36849d33e776f1 /tools/js-optimizer.js | |
parent | cf38e24d7eef9ccf6364a570e321698c675a9c60 (diff) |
optimize loop vars even if there is some code (like a phi) in the if block where the loop break is, if it does not interfere
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index f38ff08c..699ea280 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -3585,13 +3585,13 @@ function eliminate(ast, memSafe) { clearEmptyNodes(ifTrue[1]); clearEmptyNodes(ifFalse[1]); var flip = false; - if (ifFalse[1][0] && ifFalse[1][0][0] === 'break') { // canonicalize break in the if + if (ifFalse[1][0] && ifFalse[1][ifFalse[1].length-1][0] === 'break') { // canonicalize break in the if-true var temp = ifFalse; ifFalse = ifTrue; ifTrue = temp; flip = true; } - if (ifTrue[1][0] && ifTrue[1][0][0] === 'break') { + if (ifTrue[1][0] && ifTrue[1][ifTrue[1].length-1][0] === 'break') { var assigns = ifFalse[1]; clearEmptyNodes(assigns); var loopers = [], helpers = []; @@ -3628,6 +3628,17 @@ function eliminate(ast, memSafe) { } } } + // remove loop vars that are used in the if + traverse(ifTrue, function(node, type) { + if (type === 'name') { + var index = loopers.indexOf(node[1]); + if (index < 0) index = helpers.indexOf(node[1]); + if (index >= 0) { + loopers.splice(index, 1); + helpers.splice(index, 1); + } + } + }); if (loopers.length === 0) return; for (var l = 0; l < loopers.length; l++) { var looper = loopers[l]; |