Re: Re: [RFC] Normalize token_get_all() output (with flag)
| From: | Rouven Weßling | Date: | Tue, 12 Jan 2016 17:07:16 +0000 |
| Subject: | Re: Re: [RFC] Normalize token_get_all() output (with flag) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-90570@lists.php.net to get a copy of this message | ||
> On 05 Jan 2016, at 21:52, Andrea Faulds <ajf@ajf.me> 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.
>
> Thoughts?
I liked the idea so I went ahead and tested it. Code is here: https://github.com/php/php-src/pull/1727
Doing some incredibly simplistic testing using a modified version of Nikita’s PHP-Parser. It saved
~10% in memory (just parsing the parser itself and immediately discarding the result) and speed up
within the margin of error. The proposal from Sara would probably take slightly more memory than the
current code since there would be more arrays allocated.
In terms of performance that doesn’t seem like a big win. But objects are niece for another
reason: IDEs (and potentially other tools) know about them and will warn you about typos in
properties.
Best regards
Rouven