Hi Benjamin,

These are interesting optimisations. I definitely see the usefulness of detecting packed arrays and short-circuiting: I've done that in my patch to fix object/array casting, in order to avoid wasting time checking for the existence of non-string keys, even if (object)[1, 2, 3] is probably quite a rare case.

Personally, having macros for this in the Zend API might bother me slightly, because it would make it easier to rely on what is essentially an implementation detail, and therefore perhaps slightly complicate future changes to the hashtable internals.

However, so long as they're only used as hints about the shape of the array, I guess this wouldn't be an issue. In any case, I don't know if my concern here is worth worrying about.

Two further thoughts. First, are these the best names for the macros? I don't know if the meaning of “fully packed array” would be clear without an explanatory comment. Second, do you know if any other PHP functions do a similar check to JSON's php_json_determine_array_type for whether an array is free of string keys and consecutively indexed? I wonder if that could be abtracted into a zend_hash.c function.

Thanks!
--
Andrea Faulds
https://ajf.me/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to