On Tue, Jul 31, 2001 at 04:00:44PM +0200,  Marc A. Lehmann  wrote:
> Optimizing sort in this manner to gain speed is IMHO a very bad idea, as
> this optimizes sort but leaves all other functions unoptimized.

Abigail already corrected the mislogic here...

Anyhow, you should get a fairly large increase in both memory and
performance with a good inplace sort over large lists.  $a and $b are
aliases, not copies (AFAIK) but Perl has to go and allocate all the
extra memory to make a new array and copies of each scalar to return
from sort() and that eats time and memory.


> The only advantage I'd see is that inplace sort is shorter to write (which
> would be in the spirit of perl), but I think the nasty consequences of not
> being able to do in-place sorts everywhere:
> 
>    sub test {
>       if (xxx) {
>          sort inplace; # how do I do that?
>       }
>       (); # by adding smileys???
>    }
> 
> without very strange syntax. And it doesn't look very perl'ish as well.

This is the kind of thing I was worried about.  Of course, it can be
gotten around fairly simply:

    use constant NOTHING => undef;

    sub foo {
        if( xxx ) {
            sort inplace;
        }

        return NOTHING;
    }

so rather than simply falling off the end of the function you can put
an explicit return statement in.  I usually remember to do this, but
it's not as common an idiom as it should be.


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
Nature is pissed.
        http://www.unamerican.com/

Reply via email to