diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-03-17 14:43:20 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-03-17 17:56:17 -0700 |
commit | c998e415c680013d5a6fdeb2e13335ba8adb580a (patch) | |
tree | 69f82de2f53a85f8984a60b46ab7634194df5c6e | |
parent | c422f49120d0ef0304213abda37de66d3b26f4c0 (diff) |
flip a non-existent else block in simplifyIfs, if adding such a block can help
-rw-r--r-- | tests/test_other.py | 13 | ||||
-rw-r--r-- | tools/js-optimizer.js | 6 |
2 files changed, 17 insertions, 2 deletions
diff --git a/tests/test_other.py b/tests/test_other.py index 19d1790d..ded45112 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2652,3 +2652,16 @@ int main() } ''', [3, 1, 1]) + test(r''' + #include <stdio.h> + #include <stdlib.h> + + int main(int argc, char *argv[]) { + if (getenv("A") || getenv("B")) { + printf("hello world\n"); + } + printf("and that's that\n"); + return 0; + } + ''', [3, 1, 1]) + diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 88bcf503..129c493f 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -861,16 +861,18 @@ function simplifyIfs(ast) { node[1] = flipCondition(node[1]); node[2] = node[3]; node[3] = body; + body = node[2]; } else break; } else break; } // we can handle elses, but must be fully identical if (node[3] || other[3]) { - if (!node[3] || !other[3]) break; + if (!node[3]) break; if (!astCompare(node[3], other[3])) { // the elses are different, but perhaps if we flipped a condition we can do better if (astCompare(node[3], other[2])) { - // flip other + // flip other. note that other may not have had an else! add one if so; we will eliminate such things later + if (!other[3]) other[3] = ['block', []]; other[1] = flipCondition(other[1]); var temp = other[2]; other[2] = other[3]; |