# [RFC] Iteration tools

- Thread: https://externals.io/message/41639
- Original archive: https://news-web.php.net/php.internals/41639
- Started by Jared Williams on 2008-11-04T13:35:57+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #41639 — Jared Williams — 2008-11-04T13:35:57+00:00

URL: https://externals.io/message/41639#41639

"Marcus Boerger" <helly@php.net> wrote in message
news:154582775.20081103164129@marcus-boerger.de...
> Hello Ionut,
> 
>  some remarks about your proposal:
> 
> 1) You can turn any array into a Traversable using
> (Recursive)ArrayIterator. Though this solution is still slow. The issue is
> that the c-level code needs to verify the current pointer every single
time
> it uses it and that means traversing the array from the beginning. That
> said we might want to:
> a) Optimize that for cases where we don't have to. Basically when nothing
> else is pointing to the array (refcount==1) we know when the array can be
> changed and do not have to verify it always.
> b) provide a lower level array to traversable mechanism that operates on
> the current pointer provided by the array itself. That way having no need
> to verify that pointer at all.

That would be nice. 

Just written some code todo a binary search on keys, using the
ArrayIterator::seek().
It was either that or use `array_keys()` on potentially large array.

Jared
