Skip to content

Commit

Permalink
minor #4048 Tokens - inlined extractTokenKind() call on the hot path …
Browse files Browse the repository at this point in the history
…(staabm)

This PR was merged into the 2.12 branch.

Discussion
----------

Tokens - inlined extractTokenKind() call on the hot path

as identified in #4026 we inline calls to `extractTokenKind()` which leads to a 5-7% speed increase.

most calls of this method happen thru the changed code as can be seen in the blackfire profile

![image](https://user-images.githubusercontent.com/120441/46915856-1a77fe80-cfb2-11e8-9e0c-531b88059ad4.png)

Commits
-------

27c78e3 Tokens - inlined extractTokenKind() call on the hot path
  • Loading branch information
keradus committed Nov 28, 2018
2 parents 696451d + 27c78e3 commit 49c3a9e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Tokenizer/Tokens.php
Expand Up @@ -1402,7 +1402,11 @@ private function changeCodeHash($codeHash)
*/
private function registerFoundToken($token)
{
$tokenKind = $this->extractTokenKind($token);
// inlined extractTokenKind() call on the hot path
$tokenKind = $token instanceof Token
? ($token->isArray() ? $token->getId() : $token->getContent())
: (\is_array($token) ? $token[0] : $token)
;

if (!isset($this->foundTokenKinds[$tokenKind])) {
$this->foundTokenKinds[$tokenKind] = 0;
Expand All @@ -1418,7 +1422,11 @@ private function registerFoundToken($token)
*/
private function unregisterFoundToken($token)
{
$tokenKind = $this->extractTokenKind($token);
// inlined extractTokenKind() call on the hot path
$tokenKind = $token instanceof Token
? ($token->isArray() ? $token->getId() : $token->getContent())
: (\is_array($token) ? $token[0] : $token)
;

if (!isset($this->foundTokenKinds[$tokenKind])) {
return;
Expand Down

0 comments on commit 49c3a9e

Please sign in to comment.