inline single-use function across loop (#2594)
This commit is contained in:
@@ -3862,12 +3862,15 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fn instanceof AST_Function) {
|
if (fn instanceof AST_Function) {
|
||||||
|
var def;
|
||||||
if (compressor.option("inline")
|
if (compressor.option("inline")
|
||||||
&& exp === fn
|
|
||||||
&& !fn.name
|
|
||||||
&& !fn.uses_arguments
|
&& !fn.uses_arguments
|
||||||
&& !fn.uses_eval
|
&& !fn.uses_eval
|
||||||
&& fn.body.length == 1
|
&& fn.body.length == 1
|
||||||
|
&& (exp === fn ? !fn.name
|
||||||
|
: compressor.option("unused")
|
||||||
|
&& (def = exp.definition()).references.length == 1
|
||||||
|
&& !recursive_ref(compressor, def))
|
||||||
&& !fn.contains_this()
|
&& !fn.contains_this()
|
||||||
&& all(fn.argnames, function(arg) {
|
&& all(fn.argnames, function(arg) {
|
||||||
return arg.__unused;
|
return arg.__unused;
|
||||||
|
|||||||
@@ -672,3 +672,78 @@ empty_body: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline_loop_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return x();
|
||||||
|
}
|
||||||
|
for (;;) f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (;;) x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_loop_2: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for (;;) f();
|
||||||
|
function f() {
|
||||||
|
return x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (;;) x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_loop_3: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var f = function() {
|
||||||
|
return x();
|
||||||
|
};
|
||||||
|
for (;;) f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (;;) x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_loop_4: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for (;;) f();
|
||||||
|
var f = function() {
|
||||||
|
return x();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (;;) f();
|
||||||
|
var f = function() {
|
||||||
|
return x();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user