Re: Introducing "Array Of" RFC

From: Date: Mon, 20 Jan 2014 08:05:09 +0000
Subject: Re: Introducing "Array Of" RFC
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  Groups: php.internals 
Request: Send a blank email to internals+get-71305@lists.php.net to get a copy of this message
On 1/19/14, 11:31 PM, Patrick Schaaf wrote:
> Regarding the N*M checking complexity, couldn't a little bit of memory
> alleviate the problem?
> 
> For each array, have a "member type" pointer, initially NULL.
> 
> When the member type needs to be checked for the first time, and that
> "member type" pointer is not already set, do an O(N) scan of the arrray,
> testing compatibility of all members against the hinted type. Error on
> mismatch, but when all members match, remember the type behind the "member
> type" pointer.
> 
> When the member type needs to be checked and the "member type" pointer _is_
> set, just compare it to the hinted type O(1).
> 
> There must be some overhead when elements are added to an array. Either
> "when member type is set, forget it", or even "when member type is already
> set, check compatiility of the newly added element with the member type,
> and then remove member type on mismatch or keep it on match".

This means every HT becomes larger now and every time you write to a HT
you at the very least need to do one extra comparison. We use HTs
everywhere, so this would have a performance impact on every script even
if you have absolutely no intention of ever using this feature.

-Rasmus



Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc

Thread (73 messages)

« previous php.internals (#71305) next »