Re: Re: [RFC] Normalize token_get_all() output (with flag)
| From: | Andrea Faulds | Date: | Wed, 06 Jan 2016 04:08:45 +0000 |
| Subject: | Re: Re: [RFC] Normalize token_get_all() output (with flag) | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-90182@lists.php.net to get a copy of this message | ||
Hi Sara,
Sara Golemon wrote:
On Tue, Jan 5, 2016 at 12:52 PM, Andrea Faulds <ajf@ajf.me> wrote: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.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.
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/