aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-05-10 17:48:14 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-05-10 17:48:14 -0700
commita6f1fec8fb8c6fde6f5178efa236fd2b73999c63 (patch)
treeb11d6f5574c78a3cbb1d526e1bfab2b98b83b9ea /tools/js-optimizer.js
parent32444e9c75d082c97c6ee7fbca2ca53982a54957 (diff)
do not eliminate if there is a switch
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 2d0d51f9..ce67da89 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1787,6 +1787,7 @@ function eliminate(ast, memSafe) {
if (asm) var asmData = normalizeAsm(func);
//printErr('eliminate in ' + func[1]);
+
// First, find the potentially eliminatable functions: that have one definition and one use
var definitions = {};
var uses = {};
@@ -1802,6 +1803,7 @@ function eliminate(ast, memSafe) {
}
}
// examine body and note locals
+ var hasSwitch = false;
traverse(func, function(node, type) {
if (type === 'var') {
var node1 = node[1];
@@ -1833,8 +1835,19 @@ function eliminate(ast, memSafe) {
uses[name]--; // because the name node will show up by itself in the previous case
}
}
+ } else if (type == 'switch') {
+ hasSwitch = true;
}
});
+
+ // we cannot eliminate variables if there is a switch
+ if (traverse(func, function(node, type) {
+ if (type == 'switch') return true;
+ })) {
+ if (asm) denormalizeAsm(func, asmData);
+ return;
+ }
+
var potentials = {}; // local variables with 1 definition and 1 use
var sideEffectFree = {}; // whether a local variable has no side effects in its definition