Re: Re: array_seek function
| From: | Hannes Magnusson | Date: | Tue, 16 Mar 2010 22:28:47 +0000 |
| Subject: | Re: Re: array_seek function | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-47348@lists.php.net to get a copy of this message | ||
On Tue, Mar 16, 2010 at 17:12, Mikko Koppanen <mkoppanen@php.net> wrote:
> On Tue, Mar 16, 2010 at 2:12 PM, Christian Schneider
> <cschneid@cschneid.com> wrote
>> I thinks the user space implementation
>>
>> function array_seek($array, $pos)
>> {
>> $a = array_values($array);
>> return $a[$pos];
>> }
>>
>> is simple enough to not add a native function for this.
>>
>> It might not be the most efficient way to do it but I doubt that it is
>> something done frequently enough to justify another native function.
> slightly modified version of the original patch
> http://valokuva.org/~mikko/array_seek.patch.txt. The difference
> to the
I once porpoised similar patch to in_array, where it didn't reset the
position after finding the "found element".
In applications like PhD, this is extremely useful and safes us at
least 10% overhead (at the time I benchmarked it with my patch to
in_array()).
I think we wound up with something like:
while (list($key, $val) = each($array)) {
if ($key == "foobar") {
break;
}
}
next($array);
$current_index = current($array);
To get the _next_ value after the known "currently known value (or key)".
In an application like PhD (which already brought 24hours (DSSSL
24hours, xsltproc two formats compile time to) down to ~3-4minutes
(3-5formats), 10% of _language_ overhead is extremely important, so I
am all for a function that can do this (our/my goal is max 1minute...
- sorry, HD read/write is still extremely expensive :(, it simply cant
get faster then that afaict - if you have an idea; GSOC is open for
experiments.. :D).
-Hannes