Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90182 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73267 invoked from network); 6 Jan 2016 04:08:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2016 04:08:51 -0000 X-Host-Fingerprint: 2.218.134.247 unknown Received: from [2.218.134.247] ([2.218.134.247:19678] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/D8-21755-2539C865 for ; Tue, 05 Jan 2016 23:08:50 -0500 Message-ID: <51.D8.21755.2539C865@pb1.pair.com> To: internals@lists.php.net References: <77.F6.12097.81D2C865@pb1.pair.com> Date: Wed, 6 Jan 2016 04:08:45 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:42.0) Gecko/20100101 Firefox/42.0 SeaMonkey/2.39 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 2.218.134.247 Subject: Re: [PHP-DEV] Re: [RFC] Normalize token_get_all() output (with flag) From: ajf@ajf.me (Andrea Faulds) Hi Sara, Sara Golemon wrote: > On Tue, Jan 5, 2016 at 12:52 PM, Andrea Faulds wrote: >> This is more of a side-note, but maybe it's worth bringing up. Since >> token_get_all gives an array with subarrays of a regular structure, might it >> be worthwhile returning an array of objects instead? It would probably >> reduce memory usage (assuming they're objects of a Token class or something, >> not StdClass), but I don't know if it's that useful. >> > Is the internal memory usage of (new stdClass) actually less than > (array())? I know array changed a lot with PHP7, and that the kind of > array we're talking about here is a mixed (which would be the least > efficient), but I don't have the numbers to hand. No, a StdClass would consume more memory than an array, because it has a hashtable plus object overhead. But having a specific token class would much consume less, since there's no hashtable overhead for defined properties: https://gist.github.com/nikic/5015323 I believe it's even better in PHP 7. > To your question, I'm cool either way. Though if memory/efficiency is > a concern, returning an iterator would be even better, especially on > large files. Though I think that's beyond the scope of this > particular RFC. Memory probably doesn't matter, this was mostly a "what if" suggestion. > > Maybe I should keep up my "1 RFC per day" run and suggest > TOKEN_ITERATOR as yet another flag.... Maybe not. My inbox hurts. I know first-hand what making too many RFCs can do to you, so I wouldn't recommend it. Thanks! :) -- Andrea Faulds https://ajf.me/