Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41633 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21727 invoked from network); 4 Nov 2008 09:12:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2008 09:12:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=ionut.g.stan@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ionut.g.stan@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.189 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ionut.g.stan@gmail.com X-Host-Fingerprint: 209.85.128.189 fk-out-0910.google.com Received: from [209.85.128.189] ([209.85.128.189:49020] helo=fk-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/E2-25267-E0210194 for ; Tue, 04 Nov 2008 04:12:47 -0500 Received: by fk-out-0910.google.com with SMTP id 18so3663021fks.7 for ; Tue, 04 Nov 2008 01:12:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=K7yrH9gslhKTZvYvqUveDfthqgZH4Dn5lBhxbLq7hOQ=; b=F896OR5TYZWU4W1grB5IabZs9SghHSC5WbCQJ3hyy66gK0vhejntzbgAJklJ1h3yE7 1P9TBNtX8bjMJ/D/lD2ryhBFp+zR36iLUwnGrndUWF0wL+waRL79l7LwAuGzS1InrhvO 4n96WB71NTBZ4V7UFCy/38bjRj0uAQacKupms= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=XQYIGw55ztHPQxS7TO1KF++0AWX7xbiA/DgzMM+UW7Jz6N+IPKqKVgyd5yByVzNQ86 a/N5tHPR5mxXQUBS2xFWZM78q1PaDgJz+T7mDuLSME6FDiSaUShSofsd5IILc2pTRr07 kc40AwwZNgOutQRikLWxSG27KpLKQDZ+gNvRs= Received: by 10.103.137.19 with SMTP id p19mr533419mun.108.1225789963386; Tue, 04 Nov 2008 01:12:43 -0800 (PST) Received: from ?10.0.0.187? (mail.cmbtravel.ro [84.234.105.22]) by mx.google.com with ESMTPS id j10sm10297923mue.17.2008.11.04.01.12.42 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 04 Nov 2008 01:12:42 -0800 (PST) Message-ID: <491011AC.8030609@gmail.com> Date: Tue, 04 Nov 2008 11:11:08 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b1pre) Gecko/20081006 Shredder/3.0a3 MIME-Version: 1.0 To: Marcus Boerger CC: 'PHP Internals' References: <490F13A2.1020809@gmail.com> <154582775.20081103164129@marcus-boerger.de> In-Reply-To: <154582775.20081103164129@marcus-boerger.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Iteration tools From: ionut.g.stan@gmail.com (Ionut Gabriel Stan) On 11/3/2008 17:41, Marcus Boerger wrote: > 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 > > > Hi Marcus, Thanks for your answer. I had no idea there is an iterator_apply() function, I did a little bit of search after you mentioned it and found it nowhere in the docs but apparently it is present in my 5.2.6 installation. iterator_to_array() and interator_count() are very useful functions which I had knowledge of but forgot about them in my wiki. I recognize that my proposal can easily be implemented in userland code with the classes and functions that we already have, as you mentioned already. The only real advantage is the speed given by the C level code and a common, standard API for array and Traversables. This way array_map(), array_reduce() and the like could be deprecated. I always have to look in the docs or pay a little attention to my IDE to see what param goes where. Anyway, I see there's nobody else that would like this but it's ok, at least now we have namespaces so that I don't have to come up with ugly names like my_map() for these kind of helper functions. Cheers, Ionut