in reply to Why doesn't perl optimize this?
sub f { my @a; tie @a, 'SomeClass' if $_[0]; g(\@a); return [ @a ]; }
If @a or one of its elements is magical, if an element of @a overloads =, or if the REFCNT of @a or one of its elements is greater than one, then the optimisation can't be applied.
So if f's first argument is true, then the optimisation can't be applied. If g saved the reference to @a, then the optimisation can't be applied. etc.
We're talking about a massive amount of resources to avoid a rare annoyance. Make a perlcritic rule instead.
|
|---|