in reply to Inline - Subroutine Overhead
WARNING - THIS SUGGESTION IS FRAUGHT WITH PERIL
Use this at your own risk. I am not responsible if you get fired.
You could unroll the function call stack (using goto and dynamic labels) and manipulate it yourself. This is ... very poor form, requires a book of comments, and is about as fragile as bone china. But, it is possible.
Let's say you have:
That looks to be roughly what you're doing, right? Well, you can transform that code as so:my $value = foo( 3, 4, 5 ); for ( 1 .. 10_000 ) { # Blahblah my $inside_value = foo( $_, 1, 2 ); # Yadda, yadda, yadda } my $other_value = foo( 7, 8, 9 ); sub foo { my ($first, @args) = @_; do_something( $first ); return do_something_else( @args ); }
my $LABEL; my @FOO_ARGS; my $FOO_RV; $LABEL = 'FIRST'; @FOO_ARGS = ( 3, 4, 5 ); goto FOO; FIRST: my $value = $FOO_RV; $LABEL = undef; $FOO_RV = undef; for ( 1 .. 10_000 ) { # Blahblah @FOO_ARGS = ( $_, 1, 2 ); FOO: { my ($first, @args) = @FOO_ARGS; do_something( $first ); $FOO_RV = do_something_else( @args ); goto $LABEL if $LABEL; } my $inside_value = $FOO_RV; # Yadda, yadda, yadda } $LABEL = 'SECOND'; @FOO_ARGS = ( 7, 8, 9 ); goto FOO; SECOND: my $other_value = $FOO_RV; $LABEL = undef; $FOO_RV = undef;
Note: I am not advocating this type of code nor am I suggesting that you won't be hunted down like the fool you are if you implement this code and quit the next day. I'm saying that you can inline functions in Perl that are called from outside the loop and here is how.
Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
|
|---|