From: Mihai Bazon Date: Wed, 2 Oct 2013 12:31:31 +0000 (+0300) Subject: minor optimization X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=88fb83a;p=UglifyJS.git minor optimization unlikely to help in hand-written code: (something() ? foo : bar) == foo ==> something() --- diff --git a/lib/compress.js b/lib/compress.js index daac1c38..93f01482 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1882,6 +1882,32 @@ merge(Compressor.prototype, { // result. hence, force switch. reverse(null, true); } + if (/^[!=]==?$/.test(self.operator)) { + if (self.left instanceof AST_SymbolRef && self.right instanceof AST_Conditional) { + if (self.right.consequent instanceof AST_SymbolRef + && self.right.consequent.definition() === self.left.definition()) { + if (/^==/.test(self.operator)) return self.right.condition; + if (/^!=/.test(self.operator)) return self.right.condition.negate(compressor); + } + if (self.right.alternative instanceof AST_SymbolRef + && self.right.alternative.definition() === self.left.definition()) { + if (/^==/.test(self.operator)) return self.right.condition.negate(compressor); + if (/^!=/.test(self.operator)) return self.right.condition; + } + } + if (self.right instanceof AST_SymbolRef && self.left instanceof AST_Conditional) { + if (self.left.consequent instanceof AST_SymbolRef + && self.left.consequent.definition() === self.right.definition()) { + if (/^==/.test(self.operator)) return self.left.condition; + if (/^!=/.test(self.operator)) return self.left.condition.negate(compressor); + } + if (self.left.alternative instanceof AST_SymbolRef + && self.left.alternative.definition() === self.right.definition()) { + if (/^==/.test(self.operator)) return self.left.condition.negate(compressor); + if (/^!=/.test(self.operator)) return self.left.condition; + } + } + } } self = self.lift_sequences(compressor); if (compressor.option("comparisons")) switch (self.operator) {