On Tue, Jul 31, 2001 at 03:09:36PM +0200, Bart Lateur <[EMAIL PROTECTED]> wrote:
> Then couldn't a minimal "list" be an array of pointers, typically 4
> bytes each, while the scalar itself is the possibly dereferenced value,
> plus an overhead of roughly 30 bytes?

In perl, an array (lists are similar) is implemented just like that (on 32
bit machines ;). the cost of sort() in perl is mostly comparing values,
which is why perls sort uses a sorting function that tries to avoid
compares.

The problem comes from the fact that scalars are passed by value (good
idea usually), and perl implements this by copying (usually a good idea as
well).

Optimizing sort in this manner to gain speed is IMHO a very bad idea, as
this optimizes sort but leaves all other functions unoptimized.

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.

-- 
      -----==-                                             |
      ----==-- _                                           |
      ---==---(_)__  __ ____  __       Marc Lehmann      +--
      --==---/ / _ \/ // /\ \/ /       [EMAIL PROTECTED]      |e|
      -=====/_/_//_/\_,_/ /_/\_\       XX11-RIPE         --+
    The choice of a GNU generation                       |
                                                         |

Reply via email to