develooper Front page | perl.perl5.porters | Postings from July 2010

Re: [perl #76438] peephole optimiser could prune more dead code

Thread Previous | Thread Next
July 29, 2010 06:40
Re: [perl #76438] peephole optimiser could prune more dead code
Message ID:
On Tue, Jul 20, 2010 at 02:41:34PM -0700, Jan Dubois wrote:
> On Tue, 20 Jul 2010, Nicholas Clark wrote:
> > I read $a . $a as equivalent to $x . $y, where it happens that $x and $y
> > alias the same value. $a was *written* twice by the programmer, so as there
> > are two references to it, it gets accessed *exactly* twice.
> In that case I think you'll find plenty of places where it is accessed
> more often than you expect. E.g. ++$a might access $a once if it is
> just SV_pIOK, or twice if it is just SV_pNOK, because sv_inc() will first
> try to see if it can't convert the NV to an IV, triggering an additional
> FETCH call:
>     flags = SvFLAGS(sv);
>     if ((flags & (SVp_NOK|SVp_IOK)) == SVp_NOK) {
> 	/* It's (privately or publicly) a float, but not tested as an
> 	   integer, so test it to see. */
> 	(void) SvIV(sv);
> 	flags = SvFLAGS(sv);
>     }
> It is easy to guarantee that each tied variable is fetched at least once
> for each time it is mentioned in the source code, but it is extremely
> hard to guarantee that it isn't called more often: Any innocent looking
> SvIV(), SvNV() or SvPV() call anywhere in the core may trigger an
> additional call to FETCH a tied variable.
> I prefer to view this as an inefficiency, not as a bug, because I think
> FETCH should be side-effect free.

If FETCH is to be side-effect free, many of the interesting cases for using
ties disappear.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About