aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-03-27 10:34:52 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-03-27 10:34:52 -0700
commit422d65dc0603ca7c856e82425adfeee01463d2b0 (patch)
tree9f18a36de2cdbb210af08b00ff281716f9a59e14 /tools/js-optimizer.js
parente01dac87dae70222db7b8c0a8f3301b368f8b67b (diff)
optimize away individual loop vars, even if we can't remove them all
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 49bc9d11..a4c05b70 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -3964,7 +3964,7 @@ function eliminate(ast, memSafe) {
}
}
}
- if (loopers.length < assigns.length) return; // TODO: handle the case where can can just eliminate one. (we can't optimize the break, but we can remove the var at least)
+ if (loopers.length === 0) return;
for (var l = 0; l < loopers.length; l++) {
var looper = loopers[l];
var helper = helpers[l];
@@ -4016,9 +4016,24 @@ function eliminate(ast, memSafe) {
// simplify the if. we remove the if branch, leaving only the else
if (flip) {
last[1] = simplifyNotCompsDirect(['unary-prefix', '!', last[1]]);
+ var temp = last[2];
last[2] = last[3];
+ last[3] = temp;
+ }
+ if (loopers.length === assigns.length) {
+ last.pop();
+ } else {
+ var elseStats = getStatements(last[3]);
+ for (var i = 0; i < elseStats.length; i++) {
+ var stat = elseStats[i];
+ if (stat[0] === 'stat') stat = stat[1];
+ if (stat[0] === 'assign' && stat[2][0] === 'name') {
+ if (loopers.indexOf(stat[2][1]) >= 0) {
+ elseStats[i] = emptyNode();
+ }
+ }
+ }
}
- last.pop();
}
}
}