speed up equivalent_to() and AST_Switch (#1727)
This commit is contained in:
@@ -196,8 +196,7 @@ merge(Compressor.prototype, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
AST_Node.DEFMETHOD("equivalent_to", function(node){
|
AST_Node.DEFMETHOD("equivalent_to", function(node){
|
||||||
// XXX: this is a rather expensive way to test two node's equivalence:
|
return this.TYPE == node.TYPE && this.print_to_string() == node.print_to_string();
|
||||||
return this.print_to_string() == node.print_to_string();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Node.DEFMETHOD("process_expression", function(insert) {
|
AST_Node.DEFMETHOD("process_expression", function(insert) {
|
||||||
@@ -2518,7 +2517,6 @@ merge(Compressor.prototype, {
|
|||||||
self.expression = best_of_expression(expression, self.expression);
|
self.expression = best_of_expression(expression, self.expression);
|
||||||
}
|
}
|
||||||
if (!compressor.option("dead_code")) return self;
|
if (!compressor.option("dead_code")) return self;
|
||||||
var prev_block;
|
|
||||||
var decl = [];
|
var decl = [];
|
||||||
var body = [];
|
var body = [];
|
||||||
var default_branch;
|
var default_branch;
|
||||||
@@ -2547,14 +2545,16 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (aborts(branch)) {
|
if (aborts(branch)) {
|
||||||
var block = make_node(AST_BlockStatement, branch, branch).print_to_string();
|
if (body.length > 0 && !fallthrough) {
|
||||||
if (!fallthrough && prev_block === block) body[body.length - 1].body = [];
|
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);
|
body.push(branch);
|
||||||
prev_block = block;
|
|
||||||
fallthrough = false;
|
fallthrough = false;
|
||||||
} else {
|
} else {
|
||||||
body.push(branch);
|
body.push(branch);
|
||||||
prev_block = null;
|
|
||||||
fallthrough = true;
|
fallthrough = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user