Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66498 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18355 invoked from network); 6 Mar 2013 17:28:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Mar 2013 17:28:46 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain zend.com does not designate 209.85.219.43 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.219.43 mail-oa0-f43.google.com Received: from [209.85.219.43] ([209.85.219.43:64359] helo=mail-oa0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 04/E7-03015-CCC77315 for ; Wed, 06 Mar 2013 12:28:45 -0500 Received: by mail-oa0-f43.google.com with SMTP id l10so12975703oag.30 for ; Wed, 06 Mar 2013 09:28:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=4gaVZUWpk+uzfWzEQsOZtC+rnLaSrWyqdbIg0kXTik0=; b=ES1PspAqvZ/Y09YkDnvUCwkQuKPJ6BQ8Y+Pze/M0zKHCGyVPGWa7+rVGSZ3CLKMxDm 5Ul9FkVH9hljRZNGPVkhB7tj4CvOvbeEKzVvhtKY/jlIRLFQQAu7rM3UajUOe8wjFnUb EqTtejzB9uCyrqQsLCsB0lb/a3/Jv4tAGZN6uJins0d7qY20iZS72EYwSRe3m8n9w/zA Y9Ep9xhm1+4A5Y448dOUu7EHCpSjYcGbhFArmW6BJS05d7/gLaTP30RCkqiYKjn5+sSp /tq7/IVpbfIJJKIpdjx4852dwJamC+q581O1ZoOWeTGE+aUIziLVCgyUlkYWJvIrb0pJ 1KtQ== MIME-Version: 1.0 X-Received: by 10.60.20.35 with SMTP id k3mr23278198oee.119.1362590921765; Wed, 06 Mar 2013 09:28:41 -0800 (PST) Received: by 10.182.242.79 with HTTP; Wed, 6 Mar 2013 09:28:41 -0800 (PST) In-Reply-To: References: Date: Wed, 6 Mar 2013 20:28:41 +0300 Message-ID: To: Nikita Popov Cc: PHP internals , Zeev Suraski , Andi Gutmans Content-Type: multipart/alternative; boundary=e89a8fb206f2de288504d744eb0a X-Gm-Message-State: ALoCoQk1pZL+AWo+5m+8vXVt/BtUUJMUZ6MMzTPUKVJIN++43+YoPwBDpSy4g8nyXllPQQi8Tv7ds/ej9YbFkdhN1X9Wfy55B29rXuwDMUAgUvgp/3kuA860IJUqs4EwOL4jqeliOjtY Subject: Re: [PHP-DEV] Re: [VOTE] Allow non-scalar keys in foreach From: dmitry@zend.com (Dmitry Stogov) --e89a8fb206f2de288504d744eb0a Content-Type: text/plain; charset=UTF-8 On Wed, Mar 6, 2013 at 9:16 PM, Nikita Popov wrote: > On Wed, Mar 6, 2013 at 5:41 PM, Dmitry Stogov wrote: > >> Hi Nikita, >> >> few notes about the patch... >> >> - you may avoid estrndup() in zend_hash_current_key_zval_ex() for >> interned strings. >> > > Good idea, I'll do that. > >> >> - I didn't completely get why did you change the "key" operand type from >> IS_TMP_VAR to IS_VAR and how it affects performance >> As I understood now you need to allocate new zval on each loop iteration >> even for foreach over plain arrays. :( >> > > Good point, I didn't consider the performance implication the type change > would have. The intent behind that was to avoid copying the get_current_key > zval into the temporary (and destroying it then), but I didn't consider how > it affects normal arrays. This should be changed back to TMP_VAR. > It would be great. I can agree that new features may work slower, but really don't like when they slowdown existing and mach more usual cases. > > 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. --e89a8fb206f2de288504d744eb0a--