Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66570 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92684 invoked from network); 9 Mar 2013 21:48:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2013 21:48:01 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.177 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.177 mail-ob0-f177.google.com Received: from [209.85.214.177] ([209.85.214.177:59647] helo=mail-ob0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 95/61-19169-01EAB315 for ; Sat, 09 Mar 2013 16:48:00 -0500 Received: by mail-ob0-f177.google.com with SMTP id eh20so2242424obb.22 for ; Sat, 09 Mar 2013 13:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=TfuUuuf2be2MKUkRmKTfl7vUFNIRLw6DYBN1BhJUz+Q=; b=TKOmfzN6feNzOTj4oSw42rhW5OMPTQL06v9wgFA9h18uvNdMeZYBt/bfAnFUzTcwFH eMW107py/gsmGeJHetgl2sowTC/1GHlsUh2xL2SY+IpUysHSlr0JjdsbdrUGuP+UeB72 mUVDYk3Y4PauohdhUxuiDNiB/P1ZgSGAlt1QouI/O1Ih/39SHjg7j3+F85RGPf3jXI2L WZF6Cypqh617GAGJtEIdLQAPUu75C+5q1n7MJLEb8RV/L7TV9v95xfrNjsx2dxl5d0I4 oHHBNkuTXsBfkRxC7civRu0pKEBZyDu0AoKI5rHOjqPTlNPtI1Dy2r4veCb5bMEdqiCm g0gw== MIME-Version: 1.0 X-Received: by 10.182.31.109 with SMTP id z13mr5315866obh.37.1362865676749; Sat, 09 Mar 2013 13:47:56 -0800 (PST) Received: by 10.182.49.136 with HTTP; Sat, 9 Mar 2013 13:47:56 -0800 (PST) In-Reply-To: References: Date: Sat, 9 Mar 2013 22:47:56 +0100 Message-ID: To: Dmitry Stogov Cc: PHP internals , Zeev Suraski , Andi Gutmans Content-Type: multipart/alternative; boundary=14dae93b5c808a19c104d784e439 Subject: Re: [PHP-DEV] Re: [VOTE] Allow non-scalar keys in foreach From: nikita.ppv@gmail.com (Nikita Popov) --14dae93b5c808a19c104d784e439 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Mar 6, 2013 at 6:28 PM, Dmitry Stogov wrote: > >> I wonder what would be a good way to avoid allocating a temporary zval >> for the key and freeing it again. Do you think it would be okay to pass >> &EX_T((opline+1)->result.var).tmp_var into ->get_current_key() so the value >> can be written directly into it without doing extra allocs/frees? >> >> > I'm not sure it'll work. TMP_VARs don't initialize refcount, they can't be > referenced or marked as a possible root of garbage. > I took only a very quick look over the patch and didn't understand all the > details, but probably it must be possible to copy iterator key into TMP_VAR > and call copy_ctor(). > > Please, let me review the patch when it's ready (I won't be available on > March 8 and weekend). > > Thanks. Dmitry. > Here is the new patch: https://github.com/nikic/php-src/commit/a1bfc8105713eeb4e66e852b81884b567ad56020 It passes in the tmp_var in as a zval*, which can then be set using the ZVAL_* macros (basically the same way as it's done with return_value). This way we don't need any further zval allocs and frees. It also turned out that doing it this way is more convenient to use in the respective key handlers. Nikita --14dae93b5c808a19c104d784e439--