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

Re: [perl #122947] [EXPERIMENT] Lvalue references

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
October 14, 2014 20:56
Subject:
Re: [perl #122947] [EXPERIMENT] Lvalue references
Message ID:
CAHhgV8j_sBuhWwZ9g0mzV0fkHHfYxZDxh2g1U2z5Vc43J01Q7w@mail.gmail.com
On Tue, Oct 14, 2014 at 5:06 PM, H.Merijn Brand <h.m.brand@xs4all.nl> wrote:

> is that (internally) different from using the 4-arg form (which I
> prefer because it is much faster)?
>
> $ perl -wE'$_="Foo";substr $_,1,0,"x";say'
> Fxoo
> $ perl -wE'$_="Foo";substr($_,1,0)="x";say'
> Fxoo
>
> B says no
>
> $ perl -MO=Concise -wE'$_="Foo";substr($_,1,0)="x";say'
> g  <@> leave[1 ref] vKP/REFC ->(end)
> 1     <0> enter ->2
> 2     <;> nextstate(main 47 -e:1) v:%,{,469764096 ->3
> 5     <2> sassign vKS/2 ->6
> 3        <$> const[PV "Foo"] s ->4
> -        <1> ex-rv2sv sKRM*/1 ->5
> 4           <#> gvsv[*_] s ->5
> 6     <;> nextstate(main 47 -e:1) v:%,{,469764096 ->7
> -     <1> ex-sassign vKS/2 ->c
> b        <@> substr[t3] vKS/REPL1ST,3 ->c
> -           <0> ex-pushmark s ->8
> 7           <$> const[PV "x"] s ->8
> -           <1> ex-rv2sv sKRM*/1 ->9
> 8              <#> gvsv[*_] s ->9
> 9           <$> const[IV 1] s ->a
> a           <$> const[IV 0] s ->b
> c     <;> nextstate(main 47 -e:1) v:%,{,469764096 ->d
> f     <@> say vK ->g
> d        <0> pushmark s ->e
> -        <1> ex-rv2sv sK/1 ->f
> e           <#> gvsv[*_] s ->f
> -e syntax OK
>
> $ perl -MO=Concise -wE'$_="Foo";substr $_,1,0,"x";say'
> g  <@> leave[1 ref] vKP/REFC ->(end)
> 1     <0> enter ->2
> 2     <;> nextstate(main 47 -e:1) v:%,{,469764096 ->3
> 5     <2> sassign vKS/2 ->6
> 3        <$> const[PV "Foo"] s ->4
> -        <1> ex-rv2sv sKRM*/1 ->5
> 4           <#> gvsv[*_] s ->5
> 6     <;> nextstate(main 47 -e:1) v:%,{,469764096 ->7
> b     <@> substr[t3] vK/4 ->c
> -        <0> ex-pushmark s ->7
> -        <1> ex-rv2sv sKM/1 ->8
> 7           <#> gvsv[*_] s ->8
> 8        <$> const[IV 1] s ->9
> 9        <$> const[IV 0] s ->a
> a        <$> const[PV "x"] s ->b
> c     <;> nextstate(main 47 -e:1) v:%,{,469764096 ->d
> f     <@> say vK ->g
> d        <0> pushmark s ->e
> -        <1> ex-rv2sv sK/1 ->f
> e           <#> gvsv[*_] s ->f
> -e syntax OK
>

They are not identical at all.


> cmpthese (-3, {
>     arg3 => sub { my $foo = "foo"; substr ($foo, 1, 0) = "x"; },
>     arg4 => sub { my $foo = "foo"; substr  $foo, 1, 0,   "x"; },
>     });
>
>           Rate arg3 arg4
> arg3 3235869/s   -- -61%
> arg4 8401562/s 160%   --
>

I agree we that in that specific (but probably common) case that could
probably be optimized away.

Leon

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