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

Re: Short circuiting sort

david nicol
June 23, 2004 14:49
Re: Short circuiting sort
Message ID:
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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About