Actually limit sequence length.

Fix #1038
This commit is contained in:
Mihai Bazon
2016-04-12 14:15:14 +03:00
parent 3907a5e3b2
commit b5a7a231f7
2 changed files with 25 additions and 2 deletions

View File

@@ -633,6 +633,13 @@ var AST_Seq = DEFNODE("Seq", "car cdr", {
p = p.cdr;
}
},
len: function() {
if (this.cdr instanceof AST_Seq) {
return this.cdr.len() + 1;
} else {
return 2;
}
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.car._walk(visitor);

View File

@@ -673,8 +673,12 @@ merge(Compressor.prototype, {
seq = [];
};
statements.forEach(function(stat){
if (stat instanceof AST_SimpleStatement && seq.length < 2000) seq.push(stat.body);
else push_seq(), ret.push(stat);
if (stat instanceof AST_SimpleStatement && seqLength(seq) < 2000) {
seq.push(stat.body);
} else {
push_seq();
ret.push(stat);
}
});
push_seq();
ret = sequencesize_2(ret, compressor);
@@ -682,6 +686,18 @@ merge(Compressor.prototype, {
return ret;
};
function seqLength(a) {
for (var len = 0, i = 0; i < a.length; ++i) {
var stat = a[i];
if (stat instanceof AST_Seq) {
len += stat.len();
} else {
len++;
}
}
return len;
};
function sequencesize_2(statements, compressor) {
function cons_seq(right) {
ret.pop();