improve symbol replacement heuristic (#2851)
This commit is contained in:
@@ -5237,7 +5237,7 @@ merge(Compressor.prototype, {
|
||||
var name_length = d.name.length;
|
||||
var overhead = 0;
|
||||
if (compressor.option("unused") && !compressor.exposed(d)) {
|
||||
overhead = (name_length + 2 + value_length) / d.references.length;
|
||||
overhead = (name_length + 2 + value_length) / (d.references.length - d.assignments);
|
||||
}
|
||||
d.should_replace = value_length <= name_length + overhead ? fn : false;
|
||||
} else {
|
||||
|
||||
@@ -5435,3 +5435,35 @@ lvalues_def_2: {
|
||||
}
|
||||
expect_stdout: "2 NaN"
|
||||
}
|
||||
|
||||
chained_assignments: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unsafe: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
var a = [0x5e, 0xad, 0xbe, 0xef];
|
||||
var b = 0;
|
||||
b |= a[0];
|
||||
b <<= 8;
|
||||
b |= a[1];
|
||||
b <<= 8;
|
||||
b |= a[2];
|
||||
b <<= 8;
|
||||
b |= a[3];
|
||||
return b;
|
||||
}
|
||||
console.log(f().toString(16));
|
||||
}
|
||||
expect: {
|
||||
console.log("5eadbeef");
|
||||
}
|
||||
expect_stdout: "5eadbeef"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user