Re: Add is_vectorlike($array) function

From: Date: Thu, 04 May 2017 15:52:11 +0000
Subject: Re: Add is_vectorlike($array) function
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-98965@lists.php.net to get a copy of this message
On Tue, May 2, 2017 at 4:13 AM, Jesse Schalken <me@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

« previous php.internals (#98965) next »