From: Graham Knop Date: Wed, 17 Apr 2013 11:01:56 +0000 (-0400) Subject: try to avoid localizing @_ when not needed X-Git-Tag: v1.002000~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d89a7f5612058e406735db9ca4260fc54fd99247;p=gitmo%2FMoo.git try to avoid localizing @_ when not needed --- diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index dc041ec..02443df 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -389,15 +389,20 @@ sub _generate_call_code { my ($self, $name, $type, $values, $sub) = @_; $sub = \&{$sub} if blessed($sub); # coderef if blessed if (my $quoted = quoted_from_sub($sub)) { + my $local = 1; + if ($values eq '@_' || $values eq '$_[0]') { + $local = 0; + $values = '@_'; + } my $code = $quoted->[1]; if (my $captures = $quoted->[2]) { my $cap_name = qq{\$${type}_captures_for_${name}}; $self->{captures}->{$cap_name} = \$captures; Sub::Quote::inlinify( - $code, $values, Sub::Quote::capture_unroll($cap_name, $captures, 6), 1 + $code, $values, Sub::Quote::capture_unroll($cap_name, $captures, 6), $local ); } else { - Sub::Quote::inlinify($code, $values, undef, 1); + Sub::Quote::inlinify($code, $values, undef, $local); } } else { my $cap_name = qq{\$${type}_for_${name}}; diff --git a/lib/Sub/Quote.pm b/lib/Sub/Quote.pm index 37997d2..0f367f9 100644 --- a/lib/Sub/Quote.pm +++ b/lib/Sub/Quote.pm @@ -37,7 +37,11 @@ sub inlinify { $do.'my ('.$code_args.') = ('.$args.'); '.$body.' }'; } } else { - $do.($local ? 'local ' : '').'@_ = ('.$args.'); '.$code.' }'; + my $assign = ''; + if ($local || $args ne '@_') { + $assign = ($local ? 'local ' : '').'@_ = ('.$args.'); '; + } + $do.$assign.$code.' }'; } }