[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: exists $foo[7] and delete $foo[7]



Larry Wall writes:
|| Ilya Zakharevich writes:
|| : Gurusamy Sarathy writes:
|| : > So I decided to should extend exists() and delete() to cover arrays
|| : > as well.
|| : 
|| : Should not we do the same to keys()/values()/each() as well?  1/6 ;-)
|| 
|| Patches 5/6 welcome.  :-)

When it gets to the point that sparse arrays actually contain
large gaps (with no elements physically allocated for them),
there would be a great advantage in having each/keys/values.

After:

    @a[1, 1000, 1 000 000, 1 000 000 000] = (0..3);

Using:
 
    while( ($index,$value) = each(@a) ) {
        ...
    }

would be about a billion times faster than:

    for( $index = 0; $index < @a; ++$index ) {
        next unless exists $a[$index];
        $val = $a[$index];
        ...
    }

But, there is no urgency about adding each/keys/values for 5.6.

I'm at least 11/6 tuits short of generating a patch.

--
John Macdonald     jmm@jmm.pickering.elegant.com


Follow-Ups from:
Martyn Pearce <m.pearce@inpharmatica.co.uk>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]