Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41625 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43743 invoked from network); 3 Nov 2008 15:41:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Nov 2008 15:41:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:49652] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/A8-03485-0BB1F094 for ; Mon, 03 Nov 2008 10:41:37 -0500 Received: from MBOERGER-ZRH (unknown [193.142.125.1]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id DB24E11F776; Mon, 3 Nov 2008 16:41:33 +0100 (CET) Date: Mon, 3 Nov 2008 16:41:29 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <154582775.20081103164129@marcus-boerger.de> To: Ionut Gabriel Stan CC: 'PHP Internals' In-Reply-To: <490F13A2.1020809@gmail.com> References: <490F13A2.1020809@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Iteration tools From: helly@php.net (Marcus Boerger) Hello Ionut, some remarks about your proposal: 1) You can turn any array into a Traversable using (Recursive)ArrayIterator. Though this solution is still slow. The issue is that the c-level code needs to verify the current pointer every single time it uses it and that means traversing the array from the beginning. That said we might want to: a) Optimize that for cases where we don't have to. Basically when nothing else is pointing to the array (refcount==1) we know when the array can be changed and do not have to verify it always. b) provide a lower level array to traversable mechanism that operates on the current pointer provided by the array itself. That way having no need to verify that pointer at all. 2) Ther are iterator_apply(), iterator_to_array(), iterator_count() The first can be used for a lot of the things you were looking for, especially when used together with lambdas. Also not that you can use it to pass the iterator itself to the function being called easily. Still a few of the things you mention can be implemented faster in the same way iterator_apply() was done. In fact the code can be based on the lovel c-implementation provided. marcus Monday, November 3, 2008, 4:07:14 PM, you wrote: > Hello everybody, > As a result of the advice given in the thread "array_key_exists BC > break", I have written an > RFC concerning some higher order functions that, I believe, could a > helpful addition to the language. > Please note that I'm a userland developer and have no clue about PHP > internals so please > forgive any stupidities I might have said in the RFC and make the > appropriate corrections. > That also means that, if positive feedback is received, this RFC needs a > developer with PHP > internals knowledge to implement it. > The RFC can be found here: http://wiki.php.net/rfc/iteration-tools > Hoping that I've made sense in what I wrote there, please feel free to > comment as you like. > Regards, > Ionut Best regards, Marcus