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

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

From:
Nicholas Clark
Date:
June 30, 2004 11:58
Subject:
Re: optimizing Short circuiting sort method based on [M]
Message ID:
20040630185839.GW1147@plum.flirble.org
On Wed, Jun 30, 2004 at 11:42:44AM -0700, Glenn Linderman wrote:

> Thanks for describing how one would do this with a modified merge sort. 
>  I agree that there would be some benefits to using merge sort, because 
> of perl already using mergesort, but I'm uncertain that any of the code 
> could be reused, without slowing down the "full sort", which wouldn't be 
> a brilliant thing to do.

Indeed not. Slowing down the general case to benefit a special case isn't
going to get in. And I've see no evidence to counter my intuition that this
case of top M is anything but rare.

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?

Nicholas Clark



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