aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-06-07 10:45:38 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-06-07 10:45:38 -0700
commit574437453c4512eaedea5bcd4a74f8a29e6a37ba (patch)
tree0d0f8eddef9b7839991b54d7e2e958afbd5b80dc /tools/js-optimizer.js
parent20abfa85d57e796ab5fdf744643c7d3de08ae454 (diff)
properly simplify not comps in loop suffixes and elsewhere
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js46
1 files changed, 24 insertions, 22 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 8e815100..5f650332 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -950,25 +950,27 @@ function optimizeShiftsAggressive(ast) {
// we then get
// if (!(x < 5))
// or such. Simplifying these saves space and time.
-function simplifyNotComps(ast) {
- traverse(ast, function(node, type) {
- if (type == 'unary-prefix' && node[1] == '!' && node[2][0] == 'binary') {
- if (node[2][1] == '<') {
- return ['binary', '>=', node[2][2], node[2][3]];
- } else if (node[2][1] == '>') {
- return ['binary', '<=', node[2][2], node[2][3]];
- } else if (node[2][1] == '==') {
- return ['binary', '!=', node[2][2], node[2][3]];
- } else if (node[2][1] == '!=') {
- return ['binary', '==', node[2][2], node[2][3]];
- } else if (node[2][1] == '===') {
- return ['binary', '!==', node[2][2], node[2][3]];
- } else if (node[2][1] == '!==') {
- return ['binary', '===', node[2][2], node[2][3]];
- }
+function simplifyNotCompsDirect(node) {
+ if (node[0] == 'unary-prefix' && node[1] == '!' && node[2][0] == 'binary') {
+ if (node[2][1] == '<') {
+ return ['binary', '>=', node[2][2], node[2][3]];
+ } else if (node[2][1] == '>') {
+ return ['binary', '<=', node[2][2], node[2][3]];
+ } else if (node[2][1] == '==') {
+ return ['binary', '!=', node[2][2], node[2][3]];
+ } else if (node[2][1] == '!=') {
+ return ['binary', '==', node[2][2], node[2][3]];
+ } else if (node[2][1] == '===') {
+ return ['binary', '!==', node[2][2], node[2][3]];
+ } else if (node[2][1] == '!==') {
+ return ['binary', '===', node[2][2], node[2][3]];
}
- });
- return ast;
+ }
+ return node;
+}
+
+function simplifyNotComps(ast) {
+ traverse(ast, simplifyNotCompsDirect);
}
function simplifyExpressionsPost(ast) {
@@ -1217,8 +1219,7 @@ function hoistMultiples(ast) {
var temp = node[3];
node[3] = node[2];
node[2] = temp;
- node[1] = ['unary-prefix', '!', node[1]];
- simplifyNotComps(node[1]); // bake the ! into the expression
+ node[1] = simplifyNotCompsDirect(['unary-prefix', '!', node[1]]);
stat1 = node[2][1];
stat2 = node[3][1];
}
@@ -2436,7 +2437,7 @@ function eliminate(ast, memSafe) {
}
// simplify the if. we remove the if branch, leaving only the else
if (flip) {
- last[1] = simplifyNotComps(['unary-prefix', '!', last[1]]);
+ last[1] = simplifyNotCompsDirect(['unary-prefix', '!', last[1]]);
last[2] = last[3];
}
last.pop();
@@ -2574,7 +2575,8 @@ function asmLoopOptimizer(ast) {
var conditionToBreak = last[1];
stats.pop();
node[0] = 'do';
- node[1] = simplifyNotComps(['unary-prefix', '!', conditionToBreak]);
+ node[1] = simplifyNotCompsDirect(['unary-prefix', '!', conditionToBreak]);
+ return node;
}
}
});