diff options
author | Mihai Bazon <mihai@bazon.net> | 2013-10-02 15:31:31 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2013-10-02 15:31:31 +0300 |
commit | 88fb83aa813d38e21abeab2b5e4f74f02ef582c1 (patch) | |
tree | 943e7ea04da6ff63909ddd5fc984e96672047375 | |
parent | 95b4507c02b57ad15a50e4db7343bac250ed4460 (diff) | |
download | tracifyjs-88fb83aa813d38e21abeab2b5e4f74f02ef582c1.tar.gz tracifyjs-88fb83aa813d38e21abeab2b5e4f74f02ef582c1.zip |
minor optimization
unlikely to help in hand-written code:
(something() ? foo : bar) == foo ==> something()
-rw-r--r-- | lib/compress.js | 26 |
1 files changed, 26 insertions, 0 deletions
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) { |