On Tue Oct 14 08:07:44 2014, hmbrand wrote: > On Tue, 14 Oct 2014 15:43:40 +0100, "Paul \"LeoNerd\" Evans" > <leonerd@leonerd.org.uk> wrote: > > > On Tue, 14 Oct 2014 08:47:15 -0400 > > Ricardo Signes <perl.p5p@rjbs.manxome.org> wrote: > > > > > Also, we have LVALUE refs. Is this feature actually > > > related to that? > > > > The things we have that are called LVALUE are the lvalues returned by > > the substr() function so that mutations of it can affect the original: > > > > my $str = "Hello world"; > > substr( $str, 0, 5 ) = "Goodbye"; <== assignment to an LVALUE > > 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=3DConcise -wE'$_=3D"Foo";substr($_,1,0)=3D"x";say' ... > 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% -- The optimisation that makes the assignment disappear only happens if it is known to be in void context at compile time. Your benchmark subs are not equivalent to the substr assignment that you fed to B::Concise. -- Father Chrysostomos --- via perlbug: queue: perl5 status: open https://rt.perl.org/Ticket/Display.html?id=122947Thread Previous | Thread Next