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

Re: Short circuiting sort

From:
david nicol
Date:
June 23, 2004 14:49
Subject:
Re: Short circuiting sort
Message ID:
1088027335.1296.27.camel@plaza.davidnicol.com
On Sun, 2004-06-20 at 14:49, Glenn Linderman wrote:

> So, in the situation where you have a countable number of parameters as 
> the target of the sort, such as your example, or
> 
>    ($first, $second, $third, $fourth) = sort @ary;  # only sort 4 entries
> 
>    @most[ 0 .. 6 ] = sort @ary; # only sort 7 entries
> 
> the compiler could derive the hint, in a similar manner as it presently 
> (recent feature) derives the in-place optimization.

Yes, exactly.  We would begin by providing the hint for the simple cases
and gradually exapnd the range of optimized situations .  I
imagine a working intermediate stage where your first example is
optimized and your second is not, but maybe the second is already
optimized to

  ($most[0],$most[1],$most[2],$most[3],$most[4],$most[5],$most[6]) = ...

at some level, in which case we could get them both at the same time.




-- 
david nicol
    "People used to be able to read my thoughts, but
it doesn't appear to work any more. Should I eat less cheese?"
                                               -- Elizabeth Woods




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