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

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

Thread Previous | Thread Next
From:
John P. Linderman
Date:
July 9, 2004 10:10
Subject:
Re: optimizing Short circuiting sort method based on [M]
Message ID:
200407091710.NAA48941@raptor.research.att.com
Dave Mitchell replied to david nicol as follows:
> > 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;
> >                 }
> >             }
> 
> 
> No, that's for optimising away the sort block in
> 
>     @x = sort {$b cmp $a } @y;

I was afraid somebody might say that.  This breaks the promise of
stability.  The order of equal elements is now reversed from the
input order.  (I'm about to disappear on vacation, so don't
interpret my silence as lack of interest).  -- jpl

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