Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90572 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25952 invoked from network); 12 Jan 2016 18:58:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2016 18:58:48 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.217.173 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.217.173 mail-lb0-f173.google.com Received: from [209.85.217.173] ([209.85.217.173:33360] helo=mail-lb0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F8/F5-27877-6EC45965 for ; Tue, 12 Jan 2016 13:58:46 -0500 Received: by mail-lb0-f173.google.com with SMTP id x4so21100022lbm.0 for ; Tue, 12 Jan 2016 10:58:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=CXsjpXcRi8DmeKt2fDMNvtT1LK0r72bfIypM3h5GA9c=; b=Jp+hmpyFqTMcscjviRX5gsCxp0t4PqHTX1aY/4NN3CBFObj5eGUcyttY/Dt79NesEF zCTX078jEKNA2YlhT6ZGvJom5HOQBBcXtCzsnnHDLhHiRvJ1FSd5QquLZYfsMi2zfvdP wuKcHQfkNXMzKl/chtYN+evDzvs2Y6/1OY4L+Srdmy6Lh2SnLs3hYx9mHuIli+uWNVup svqm27eq7JsbbHcbi9hmYcO0gzWJr2RWM0ESoWvvzFclSYnfdZ1UD1FUBF7QYmu2Xlb4 yBxnR3oxrctShsdYn4PtEdabR9fi/kdybeZ13Wp9w9U9Qak/msCr9/R2PETuIVKA+wf9 3HcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=CXsjpXcRi8DmeKt2fDMNvtT1LK0r72bfIypM3h5GA9c=; b=Z70hY0bmftcbXK9BSOnsTou3xQiaWd3gNcfR1dbNX0Rq6Yto+JLbymlfMegGEiko9w vzQcavuwAU/PUyEw63kxmsAa3e0W28kkXFq11M2FC3FRZQ6hBHA8hkAu+KTKBO/5Kpmu bG1oYZnJaEJRCSyPGu1tVfVOJEKiqLQryMBO3NtkY258y10TCAJ/g5oNCsD5wqzmCqFG ctij/51hcM6D9ID5G9Q5BAA1XwL5IqENUnr9IGddLRMWneN5hB72BxG7NA7ZPDxYsjKq mhoHDOTYlY9LsFxXhAURngkaq36x2FbUOyJBAWGXc5ULq4As63YOMGbR+h5jnrycdB66 Lu4Q== X-Gm-Message-State: ALoCoQlX6DbWxapVdXmvvnUNyZPRiFsBbwRjHm3u2/2WCulQ/SvJTFbE4gWqhUA65aGtkcK9DWmJJMgPxk3awMyLn4GTA9fksw== MIME-Version: 1.0 X-Received: by 10.112.135.131 with SMTP id ps3mr17225846lbb.68.1452625122543; Tue, 12 Jan 2016 10:58:42 -0800 (PST) Sender: php@golemon.com Received: by 10.112.37.44 with HTTP; Tue, 12 Jan 2016 10:58:42 -0800 (PST) X-Originating-IP: [2620:10d:c090:200::5:e8ad] In-Reply-To: References: <77.F6.12097.81D2C865@pb1.pair.com> Date: Tue, 12 Jan 2016 10:58:42 -0800 X-Google-Sender-Auth: 1scwBSrqZl-PgHqoporbFTxBWsM Message-ID: To: =?UTF-8?Q?Rouven_We=C3=9Fling?= Cc: Andrea Faulds , PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: [RFC] Normalize token_get_all() output (with flag) From: pollita@php.net (Sara Golemon) On Tue, Jan 12, 2016 at 9:07 AM, Rouven We=C3=9Fling = wrote: >> On 05 Jan 2016, at 21:52, Andrea Faulds wrote: >> This is more of a side-note, but maybe it's worth bringing up. Since tok= en_get_all gives an array with subarrays of a regular structure, might it b= e worthwhile returning an array of objects instead? It would probably reduc= e memory usage (assuming they're objects of a Token class or something, not= StdClass), but I don't know if it's that useful. >> > > I liked the idea so I went ahead and tested it. Code is here: https://git= hub.com/php/php-src/pull/1727 > > Doing some incredibly simplistic testing using a modified version of Niki= ta=E2=80=99s PHP-Parser. > It saved ~10% in memory (just parsing the parser itself and immediately d= iscarding the > result) and speed up within the margin of error. The proposal from Sara w= ould probably > take slightly more memory than the current code since there would be more= arrays allocated. > Nice! I'll say one thing though: If we're going to introduce a class, I'm tempted to leave token_get_all alone (or at least limit its changes to what's in the current porposal), and have the PhpToken class implement its own static method to do the same thing. This avoid overloading token_get_all() with a bunch of behaviors and allows us to have some broader choice of actions with PhpToken::scan(). i.e. An iteration version which would probably have nice perf wins, or a callback version, etc... This also minimizes the bike-shedding risk while we try out ideas. How does this sound? 1. Keep the current RFC basically as is. It's a minor addition to token_get_all() which can be slotted into existing code to improve readability, but offers little advantage beyond that. 2. Make a new extension to prototype this PhpToken class outside of the php-src tree, add all the extra goodies we want (array of token return, iterator of token return, extra info, limited info, etc...) 3. When this extension is good and solid, propose merging into core. I had reserved the github.com/phplang project for the specification, but didn't end up using it. We can share a repo there if you'd like. -Sara