diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-29 22:08:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-29 22:08:26 +0800 |
commit | f1a833a7aa4204411c33c7419e94e8c6c87afe23 (patch) | |
tree | faf66ab34600351e377f303d44f2e1da26e9e04c /lib | |
parent | 2e41cd6394ad389080b446c20f519fc3920f81c7 (diff) | |
download | tracifyjs-f1a833a7aa4204411c33c7419e94e8c6c87afe23.tar.gz tracifyjs-f1a833a7aa4204411c33c7419e94e8c6c87afe23.zip |
speed up `equivalent_to()` and `AST_Switch` (#1727)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index 66a6a18b..786fc567 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -196,8 +196,7 @@ merge(Compressor.prototype, { }); AST_Node.DEFMETHOD("equivalent_to", function(node){ - // XXX: this is a rather expensive way to test two node's equivalence: - return this.print_to_string() == node.print_to_string(); + return this.TYPE == node.TYPE && this.print_to_string() == node.print_to_string(); }); AST_Node.DEFMETHOD("process_expression", function(insert) { @@ -2518,7 +2517,6 @@ merge(Compressor.prototype, { self.expression = best_of_expression(expression, self.expression); } if (!compressor.option("dead_code")) return self; - var prev_block; var decl = []; var body = []; var default_branch; @@ -2547,14 +2545,16 @@ merge(Compressor.prototype, { } } if (aborts(branch)) { - var block = make_node(AST_BlockStatement, branch, branch).print_to_string(); - if (!fallthrough && prev_block === block) body[body.length - 1].body = []; + if (body.length > 0 && !fallthrough) { + var prev = body[body.length - 1]; + if (prev.body.length == branch.body.length + && make_node(AST_BlockStatement, prev, prev).equivalent_to(make_node(AST_BlockStatement, branch, branch))) + prev.body = []; + } body.push(branch); - prev_block = block; fallthrough = false; } else { body.push(branch); - prev_block = null; fallthrough = true; } } |