develooper Front page | perl.perl5.porters | Postings from January 2014

[perl #121077] [PATCH] Optimise 'my $x; my $y' into 'my ($x, $y)'

Thread Previous | Thread Next
From:
Tony Cook via RT
Date:
January 28, 2014 00:16
Subject:
[perl #121077] [PATCH] Optimise 'my $x; my $y' into 'my ($x, $y)'
Message ID:
rt-4.0.18-11266-1390868179-1129.121077-15-0@perl.org
On Mon Jan 27 16:02:45 2014, perl5-porters@perl.org wrote:
> Tony Cook wrote:
> > One issue with both patches is deparsing:
> >
> > tony@mars:.../git/perl2$ ./perl -Ilib -MO=Deparse -e 'sub foo { my
> > $x; my $y; 1 }'
> > sub foo {
> >     my($x, $y);
> >     1;
> > }
> > -e syntax OK
> 
> What is wrong with that?  It shows how perl understands the code.
> Evaluating it produces an op tree that behaves identically.

The padrange optimization which this is built on, does preserve the deparse:

$ ~/perl/blead/bin/perl5.19.8 -MO=Deparse -e 'sub foo { my ($x, $y); my $z; 1 }'
sub foo {
    my($x, $y);
    my $z;
    1;
}
-e syntax OK

even though it's internally composed into a single padrange:

$ ~/perl/blead/bin/perl5.19.8 -MO=Concise,foo -e 'sub foo { my ($x, $y); my $z; 1 }'
main::foo:
5  <1> leavesub[1 ref] K/REFC,1 ->(end)
-     <@> lineseq KP ->5
1        <;> nextstate(main 1 -e:1) v ->2
-        <@> list vKP ->-
2           <0> padrange[$x:1,3; $y:1,3; $z:2,3] vM/LVINTRO,3 ->3
-           <0> padsv[$x:1,3] vM/LVINTRO ->-
-           <0> padsv[$y:1,3] vM/LVINTRO ->-
-        <;> nextstate(main 2 -e:1) v ->-
-        <0> padsv[$z:2,3] vM/LVINTRO ->3
3        <;> nextstate(main 3 -e:1) v:{ ->4
4        <$> const[IV 1] s ->5
-e syntax OK

Tony

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=121077

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About