in-place dead_code

This commit is contained in:
alexlamsl 2017-06-16 15:16:33 +08:00
parent bfbac53762
commit c2174d06b2

View File

@ -670,7 +670,7 @@ merge(Compressor.prototype, {
CHANGED = false;
statements = eliminate_spurious_blocks(statements);
if (compressor.option("dead_code")) {
statements = eliminate_dead_code(statements, compressor);
eliminate_dead_code(statements, compressor);
}
if (compressor.option("if_return")) {
statements = handle_if_return(statements, compressor);
@ -1062,35 +1062,37 @@ merge(Compressor.prototype, {
};
function eliminate_dead_code(statements, compressor) {
var has_quit = false;
var orig = statements.length;
var has_quit;
var self = compressor.self();
statements = statements.reduce(function(a, stat){
if (has_quit) {
extract_declarations_from_unreachable_code(compressor, stat, a);
} else {
for (var i = 0, n = 0, len = statements.length; i < len; i++) {
var stat = statements[i];
if (stat instanceof AST_LoopControl) {
var lct = compressor.loopcontrol_target(stat);
if ((stat instanceof AST_Break
if (stat instanceof AST_Break
&& !(lct instanceof AST_IterationStatement)
&& loop_body(lct) === self) || (stat instanceof AST_Continue
&& loop_body(lct) === self)) {
&& loop_body(lct) === self
|| stat instanceof AST_Continue
&& loop_body(lct) === self) {
if (stat.label) {
remove(stat.label.thedef.references, stat);
}
} else {
a.push(stat);
statements[n++] = stat;
}
} else {
a.push(stat);
statements[n++] = stat;
}
if (aborts(stat)) has_quit = true;
if (aborts(stat)) {
has_quit = statements.slice(i + 1);
break;
}
}
statements.length = n;
CHANGED = n != len;
if (has_quit) has_quit.forEach(function(stat) {
extract_declarations_from_unreachable_code(compressor, stat, statements);
});
}
return a;
}, []);
CHANGED = statements.length != orig;
return statements;
};
function sequencesize(statements, compressor) {
if (statements.length < 2) return;
@ -1117,7 +1119,7 @@ merge(Compressor.prototype, {
statements.length = n;
sequencesize_2(statements, compressor);
CHANGED = statements.length != len;
};
}
function sequencesize_2(statements, compressor) {
function cons_seq(right) {