in reply to Re: Re: Re: Re: aliasing
in thread aliasing
The relevant piece of code is this
if (GIMME == G_ARRAY) { MARK++; while (MARK < SP) { tmp = *MARK; *MARK++ = *SP; *SP-- = tmp; } /* safe as long as stack cannot get extended in the above */ SP = oldsp; }
which is roughly equivalent to
( $MARK, $SP ) = ( 0, $#array ); while( $MARK < $SP ) { $tmp = $array[ $mark ]; $array[ $MARK++ } = $array[ $SP ]; $array[ $SP-- ] = tmp; }
which suggests that if the argument to reverse is a single array, rather than stack the array to create @_, the stack pointer is effectively pointed at the top of the array. This is born out (but not confirmed--I can;t find the relevant part of the source) by doing
@r = reverse 1, @r;
when substantial memory growth occurs. In this case, @_ has to be built fresh to incorporate the extra element.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Re: aliasing
by ysth (Canon) on Jan 13, 2004 at 01:35 UTC | |
by BrowserUk (Patriarch) on Jan 13, 2004 at 02:03 UTC |