On Tue, May 2, 2017 at 4:13 AM, Jesse Schalken <m...@jesseschalken.com> wrote: > The problem is that this function is O(n), but in PHP7 an array that is > vector-like is likely to be packed and without holes (HT_IS_PACKED(x) && > HT_IS_WITHOUT_HOLES(x)), in which case it is known to be vector-like > without needing to iterate over it, > Just want to underline the "is likely to be" part of this sentence. The implementation can't assume an array is not vector-like just because those checks fail. It's possible to manipulate an array into being vector-like, but not packed, or having holes.
Not really commenting on the proposal yet, which I'm a big shoulder-shruggy about. Just highlighting the caveat for any eventual implementation. We can short-circuit the O(n) loop if it *is* packed/no-holes, but if not then we need to walk it to be certain. This is probably fine since this check is likely used in places where the array is expected to be vector like and non-vector should be a slow path anyway. -Sara -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php