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

Re: optimizing Short circuiting sort method based on [M]

From:
david nicol
Date:
July 8, 2004 18:36
Subject:
Re: optimizing Short circuiting sort method based on [M]
Message ID:
1089336949.996.258.camel@plaza.davidnicol.com
On Wed, 2004-06-30 at 14:48, Dave Mitchell wrote:
> On Wed, Jun 30, 2004 at 07:58:40PM +0100, Nicholas Clark wrote:
> > Does the peephole optimiser currently have any way to optimise
> > 
> >   @a = reverse sort @b
> > 
> > into
> > 
> >   @a = sort {$b cmp $a} $b;
> > 
> > but without the explicit sort comparison?
> 
> Shouldn't be too difficult.

There's some reverse-handling code in pp_sort which I took
to be responding to a hint that

	reverse sort ...

has been encountered:


            if (PL_op->op_private & OPpSORT_REVERSE) {
                SV **p = sorting_av ? AvARRAY(av) : ORIGMARK+1;
                SV **q = p+max-1;
                while (p < q) {
                    SV *tmp = *p;
                    *p++ = *q;
                    *q-- = tmp;
                }
            }






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