Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96482 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56302 invoked from network); 19 Oct 2016 13:15:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Oct 2016 13:15:42 -0000 X-Host-Fingerprint: 176.248.3.153 unknown Received: from [176.248.3.153] ([176.248.3.153:26986] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9C/27-14749-EF177085 for ; Wed, 19 Oct 2016 09:15:42 -0400 Message-ID: <9C.27.14749.EF177085@pb1.pair.com> To: internals@lists.php.net References: <20161019104501.453BD5FAB8@mx.zeyos.com> Date: Wed, 19 Oct 2016 14:15:38 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:43.0) Gecko/20100101 Firefox/43.0 SeaMonkey/2.40 MIME-Version: 1.0 In-Reply-To: <20161019104501.453BD5FAB8@mx.zeyos.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 176.248.3.153 Subject: Re: [PHP-DEV] Exploit fully packed array/hash property From: ajf@ajf.me (Andrea Faulds) 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/