diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-11-05 13:13:06 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-11-05 13:13:06 +0200 |
commit | 774f2ded9422903f082f0291ec69c7a6e2edfcaf (patch) | |
tree | 5346c5cee1b243d40f7a55998df3eba18ba633e2 /lib/compress.js | |
parent | 85af942d64e007524d76454baf80011c3ecda2ce (diff) | |
download | tracifyjs-774f2ded9422903f082f0291ec69c7a6e2edfcaf.tar.gz tracifyjs-774f2ded9422903f082f0291ec69c7a6e2edfcaf.zip |
minor optimization
for `==` or `!=` against a constant, prefer to display the constant first.
should help a bit after gzip, i.e.:
typeof foo=="undefined"
^^^^^^ ^^^^^^^^^^^^^
vs:
"undefined"==typeof foo
^^^^^^^^^^^^^^^^^^^ (longer sequence that could repeat)
idea stolen from closure.
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/lib/compress.js b/lib/compress.js index fe212b42..5cbb31c9 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1489,21 +1489,15 @@ merge(Compressor.prototype, { // XXX: intentionally falling down to the next case case "==": case "!=": - if (self.left instanceof AST_UnaryPrefix - && self.left.operator == "typeof" - && self.right instanceof AST_String - && self.right.value == "undefined") { - if (!(self.left.expression instanceof AST_SymbolRef) - || !self.left.expression.undeclared()) { - self.left = self.left.expression; - self.right = make_node(AST_Undefined, self.right).optimize(compressor); - if (self.operator.length == 2) self.operator += "="; - } + if (self.right instanceof AST_Constant && !(self.left instanceof AST_Constant)) { + var tmp = self.left; + self.left = self.right; + self.right = tmp; } - else if (self.left instanceof AST_String - && self.left.value == "undefined" - && self.right instanceof AST_UnaryPrefix - && self.right.operator == "typeof") { + if (self.left instanceof AST_String + && self.left.value == "undefined" + && self.right instanceof AST_UnaryPrefix + && self.right.operator == "typeof") { if (!(self.right.expression instanceof AST_SymbolRef) || !self.right.expression.undeclared()) { self.left = self.right.expression; |