Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80969 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92951 invoked from network); 22 Jan 2015 10:38:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jan 2015 10:38:12 -0000 Authentication-Results: pb1.pair.com header.from=ben.coutu@zeyos.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ben.coutu@zeyos.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zeyos.com designates 109.70.220.166 as permitted sender) X-PHP-List-Original-Sender: ben.coutu@zeyos.com X-Host-Fingerprint: 109.70.220.166 unknown Received: from [109.70.220.166] ([109.70.220.166:48991] helo=mx.zeyon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 43/B5-61273-213D0C45 for ; Thu, 22 Jan 2015 05:38:12 -0500 Received: from localhost (mx.zeyon.net [127.0.0.1]) by mx.zeyon.net (Postfix) with ESMTP id DD8255F8EE for ; Thu, 22 Jan 2015 11:38:07 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mx.zeyon.net Received: from mx.zeyon.net ([127.0.0.1]) by localhost (mx.zeyon.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nwogshlVFmxX for ; Thu, 22 Jan 2015 11:38:07 +0100 (CET) Received: from cloud.zeyos.com (unknown [109.70.220.163]) by mx.zeyon.net (Postfix) with ESMTPA id 5A0845F8D7; Thu, 22 Jan 2015 11:38:04 +0100 (CET) Date: Thu, 22 Jan 2015 11:38:04 +0100 To: Nikita Popov Cc: Dmitry Stogov , Xinchen Hui , "internals@lists.php.net" MIME-Version: 1.0 X-Mailer: ZeyOS Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Message-ID: <20150122103807.DD8255F8EE@mx.zeyon.net> Subject: Re: [PHP-DEV] Improvements to for-each implementation From: ben.coutu@zeyos.com (Benjamin Coutu) Hi Nikita,=0A=0AI would suggest using the proposal for the by-value case an= d sticking with the current behavior for the by-reference case as you sugge= sted. Granted, we then cannot remove the internal pointer all together, but= we would just use it for the less common by-reference case as well as for = the legacy reset/next functions, of course. This would still improve most f= or-each traversals. At least we then wouldn't have to find a replacement so= lution for rest/prev/next/end. Moreover we can then move the internal posit= ion pointer out of the hashtable structure into zend_array because it is on= ly used for userland arrays, not other hash tables (such as object properti= es or internal structures that build upon the hashtable struct).=0A=0AThank= s,=0A=0ABen=0A=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Original =3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=0AFrom: Nikita Popov =0ATo: Benjamin Cou= tu =0ADate: Thu, 22 Jan 2015 10:53:19 +0100=0ASubject:= Re: [PHP-DEV] Improvements to for-each implementation=0A=0ADoing this was = the idea I had in mind as well, i.e. change the semantics of=0Aforeach to s= ay that it will always work on a copy for by-value iteration=0A(which ironi= cally avoids having to actually copy it). Note that this will=0Adiffer from= the current behavior in a number of ways. In particular it=0Ameans that ch= anges to arrays that were references prior to iteration will=0Anot influenc= e the iteration.=0A=0AThe real question is what we should do in the by-refe= rence case. Given that=0Awe need to acquire references to elements of the o= riginal array we can't=0Areasonably work with copy-semantics (at least I do= n't see how). So would we=0Ajust stick with the previous behavior (using th= e hash position hack) for=0Athat?=0A=0ANikita