more sequencesizing (WIP)
This commit is contained in:
@@ -189,6 +189,7 @@ function Compressor(options, false_by_default) {
|
||||
}
|
||||
if (compressor.option("sequences")) {
|
||||
statements = sequencesize(statements, compressor);
|
||||
statements = sequencesize_2(statements, compressor);
|
||||
}
|
||||
if (compressor.option("if_return")) {
|
||||
statements = handle_if_return(statements, compressor);
|
||||
@@ -371,6 +372,52 @@ function Compressor(options, false_by_default) {
|
||||
return ret;
|
||||
};
|
||||
|
||||
function sequencesize_2(statements, compressor) {
|
||||
var ret = [], prev = null;
|
||||
statements.forEach(function(stat){
|
||||
if (prev) {
|
||||
if (stat instanceof AST_For && stat.init && !(stat.init instanceof AST_Definitions)) {
|
||||
if (prev.body instanceof AST_Seq) {
|
||||
prev.body.add(stat.init);
|
||||
prev.body = prev.body.optimize(compressor);
|
||||
stat.init = prev.body;
|
||||
} else {
|
||||
stat.init = AST_Seq.cons(prev.body, stat.init).optimize(compressor);
|
||||
}
|
||||
ret.pop();
|
||||
}
|
||||
else if (stat instanceof AST_For && !stat.init) {
|
||||
stat.init = prev.body;
|
||||
ret.pop();
|
||||
}
|
||||
else if (stat instanceof AST_If) {
|
||||
if (prev.body instanceof AST_Seq) {
|
||||
prev.body.add(stat.condition);
|
||||
prev.body = prev.body.optimize(compressor);
|
||||
stat.condition = prev.body;
|
||||
} else {
|
||||
stat.condition = AST_Seq.cons(prev.body, stat.condition).optimize(compressor);
|
||||
}
|
||||
ret.pop();
|
||||
}
|
||||
else if (stat instanceof AST_With) {
|
||||
if (prev.body instanceof AST_Seq) {
|
||||
prev.body.add(stat.expression);
|
||||
prev.body = prev.body.optimize(compressor);
|
||||
stat.expression = prev.body;
|
||||
} else {
|
||||
stat.expression = AST_Seq.cons(prev.body, stat.expression).optimize(compressor);
|
||||
}
|
||||
ret.pop();
|
||||
}
|
||||
}
|
||||
ret.push(stat);
|
||||
prev = stat instanceof AST_SimpleStatement ? stat : null;
|
||||
});
|
||||
CHANGED = ret.length != statements.length;
|
||||
return ret;
|
||||
};
|
||||
|
||||
function join_consecutive_vars(statements, compressor) {
|
||||
var prev = null;
|
||||
return statements.reduce(function(a, stat){
|
||||
|
||||
Reference in New Issue
Block a user