in-place dead_code
This commit is contained in:
parent
bfbac53762
commit
c2174d06b2
|
|
@ -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 {
|
||||
if (stat instanceof AST_LoopControl) {
|
||||
var lct = compressor.loopcontrol_target(stat);
|
||||
if ((stat instanceof AST_Break
|
||||
&& !(lct instanceof AST_IterationStatement)
|
||||
&& 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);
|
||||
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
|
||||
&& !(lct instanceof AST_IterationStatement)
|
||||
&& 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;
|
||||
}
|
||||
if (aborts(stat)) has_quit = true;
|
||||
} else {
|
||||
statements[n++] = stat;
|
||||
}
|
||||
return a;
|
||||
}, []);
|
||||
CHANGED = statements.length != orig;
|
||||
return statements;
|
||||
};
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user