Don't swap binary ops when "use asm" is in effect.

Refs #167
This commit is contained in:
Mihai Bazon
2013-06-07 12:51:23 +03:00
parent a4889a0f2e
commit 02a84385a0
2 changed files with 12 additions and 8 deletions

View File

@@ -945,6 +945,9 @@ TreeWalker.prototype = {
if (x instanceof type) return x; if (x instanceof type) return x;
} }
}, },
has_directive: function(type) {
return this.find_parent(AST_Scope).has_directive(type);
},
in_boolean_context: function() { in_boolean_context: function() {
var stack = this.stack; var stack = this.stack;
var i = stack.length, self = stack[--i]; var i = stack.length, self = stack[--i];

View File

@@ -1765,14 +1765,15 @@ merge(Compressor.prototype, {
var commutativeOperators = makePredicate("== === != !== * & | ^"); var commutativeOperators = makePredicate("== === != !== * & | ^");
OPT(AST_Binary, function(self, compressor){ OPT(AST_Binary, function(self, compressor){
function reverse(op, force) { var reverse = compressor.has_directive("use asm") ? noop
if (force || !(self.left.has_side_effects() || self.right.has_side_effects())) { : function(op, force) {
if (op) self.operator = op; if (force || !(self.left.has_side_effects() || self.right.has_side_effects())) {
var tmp = self.left; if (op) self.operator = op;
self.left = self.right; var tmp = self.left;
self.right = tmp; self.left = self.right;
} self.right = tmp;
}; }
};
if (commutativeOperators(self.operator)) { if (commutativeOperators(self.operator)) {
if (self.right instanceof AST_Constant if (self.right instanceof AST_Constant
&& !(self.left instanceof AST_Constant)) { && !(self.left instanceof AST_Constant)) {