aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-28 15:16:59 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-28 15:16:59 -0800
commitf705c72430d292432c81737ed424729e56385ea9 (patch)
tree4ce71f6f6fd6fa3e13cd6e1394481fc3f336b8cb /tools/js-optimizer.js
parentab12dc1380d89298f289215087ee94a65e37acca (diff)
do not turn shifts into slow additions in optimizeShifts
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js25
1 files changed, 10 insertions, 15 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 6cd1fbcc..248ec9cd 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -492,7 +492,6 @@ function optimizeShifts(ast) {
function needsShift(name) {
return vars[name] && vars[name].primaryShift >= 0;
}
-
traverse(fun, function(node, type) { // add shift to assignments
if (node[0] == 'assign' && node[1] === true && node[2][0] == 'name' && needsShift(node[2][1])) {
node[3] = ['binary', '>>', node[3], ['num', vars[node[2][1]].primaryShift]];
@@ -519,25 +518,21 @@ function optimizeShifts(ast) {
while (more) { // collapse shifts and unshifts, completing the optimization
more = false;
traverse(fun, function(node, type) {
- if (node[0] == 'binary' && node[1] in SIMPLE_SHIFTS && node[2][0] == 'binary' && node[2][1] in SIMPLE_SHIFTS) {
+ if (node[0] == 'binary' && node[1] in SIMPLE_SHIFTS && node[2][0] == 'binary' && node[2][1] in SIMPLE_SHIFTS &&
+ node[3][0] == 'num' && node[2][3][0] == 'num') { // do not turn a << b << c into a << b + c; while logically identical, it is slower
more = true;
var combinedShift = '>>';
var sign1 = node[1] == '>>' ? 1 : -1;
var sign2 = node[2][1] == '>>' ? 1 : -1;
var total = 0;
- if (node[3][0] == 'num' && node[2][3][0] == 'num') {
- total = ['num', sign1*node[3][1] + sign2*node[2][3][1]];
- if (total[1] < 0) {
- combinedShift = '<<';
- total[1] *= -1;
- }
- if (total[1] == 0) {
- // XXX this may be wrong, if we removed a |0 that assumed we had this >> which |0's anyhow!
- return node[2][2];
- }
- } else {
- combinedShift = node[1];
- total = ['binary', sign1 == sign2 ? '+' : '-', node[3], node[2][3]];
+ total = ['num', sign1*node[3][1] + sign2*node[2][3][1]];
+ if (total[1] < 0) {
+ combinedShift = '<<';
+ total[1] *= -1;
+ }
+ if (total[1] == 0) {
+ // XXX this may be wrong, if we removed a |0 that assumed we had this >> which |0's anyhow!
+ return node[2][2];
}
return ['binary', combinedShift, node[2][2], total];
}