in-place join_vars
This commit is contained in:
parent
f044a8efa4
commit
eca96f1905
|
|
@ -679,7 +679,7 @@ merge(Compressor.prototype, {
|
||||||
statements = sequencesize(statements, compressor);
|
statements = sequencesize(statements, compressor);
|
||||||
}
|
}
|
||||||
if (compressor.option("join_vars")) {
|
if (compressor.option("join_vars")) {
|
||||||
statements = join_consecutive_vars(statements, compressor);
|
join_consecutive_vars(statements, compressor);
|
||||||
}
|
}
|
||||||
if (compressor.option("collapse_vars")) {
|
if (compressor.option("collapse_vars")) {
|
||||||
collapse(statements, compressor);
|
collapse(statements, compressor);
|
||||||
|
|
@ -1173,8 +1173,9 @@ merge(Compressor.prototype, {
|
||||||
};
|
};
|
||||||
|
|
||||||
function join_consecutive_vars(statements, compressor) {
|
function join_consecutive_vars(statements, compressor) {
|
||||||
var prev = null;
|
for (var i = 0, j = -1, len = statements.length; i < len; i++) {
|
||||||
return statements.reduce(function(a, stat){
|
var stat = statements[i];
|
||||||
|
var prev = statements[j];
|
||||||
if (stat instanceof AST_Definitions && prev && prev.TYPE == stat.TYPE) {
|
if (stat instanceof AST_Definitions && prev && prev.TYPE == stat.TYPE) {
|
||||||
prev.definitions = prev.definitions.concat(stat.definitions);
|
prev.definitions = prev.definitions.concat(stat.definitions);
|
||||||
CHANGED = true;
|
CHANGED = true;
|
||||||
|
|
@ -1183,21 +1184,18 @@ merge(Compressor.prototype, {
|
||||||
&& prev instanceof AST_Var
|
&& prev instanceof AST_Var
|
||||||
&& (!stat.init || stat.init.TYPE == prev.TYPE)) {
|
&& (!stat.init || stat.init.TYPE == prev.TYPE)) {
|
||||||
CHANGED = true;
|
CHANGED = true;
|
||||||
a.pop();
|
|
||||||
if (stat.init) {
|
if (stat.init) {
|
||||||
stat.init.definitions = prev.definitions.concat(stat.init.definitions);
|
stat.init.definitions = prev.definitions.concat(stat.init.definitions);
|
||||||
} else {
|
} else {
|
||||||
stat.init = prev;
|
stat.init = prev;
|
||||||
}
|
}
|
||||||
a.push(stat);
|
statements[j] = stat;
|
||||||
prev = stat;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
prev = stat;
|
statements[++j] = stat;
|
||||||
a.push(stat);
|
|
||||||
}
|
}
|
||||||
return a;
|
}
|
||||||
}, []);
|
statements.length = j + 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user