Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Why doesn't perl optimize this?

by ikegami (Pope)
on Jun 04, 2013 at 04:35 UTC ( #1036886=note: print w/ replies, xml ) Need Help??


in reply to Why doesn't perl optimize this?

Note that It can't safely be optimised that way at compile-time. Consider

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.


Comment on Re: Why doesn't perl optimize this?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036886]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (13)
As of 2015-07-02 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (31 votes), past polls