Skip to content

Commit

Permalink
minor #4046 Token - Added fast isset() path to token->equals() (staabm)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.12 branch.

Discussion
----------

Token - Added fast isset() path to token->equals()

looking up the existance of a property via isset() is waaaaay faster then array_key_exists().
we still need array_key_exists() as a fallback, when properties exist with a null-value to work properly. this case is very rare, therefore this can be considered a speedup.

this change speeds up php-cs-fixer by 5.6%.

![image](https://user-images.githubusercontent.com/120441/46920181-bd4c6f00-cfea-11e8-8145-069ff58f63c4.png)

Commits
-------

577a46a Added fast isset() path to token->equals()
  • Loading branch information
keradus committed Nov 28, 2018
2 parents 727caca + 577a46a commit 696451d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Tokenizer/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ public function equals($other, $caseSensitive = true)
return $this->content === $otherPrototype;
}

if (array_key_exists(0, $otherPrototype) && $this->id !== $otherPrototype[0]) {
if ($this->id !== $otherPrototype[0]) {
return false;
}

if (array_key_exists(1, $otherPrototype)) {
if (isset($otherPrototype[1])) {
if ($caseSensitive) {
if ($this->content !== $otherPrototype[1]) {
return false;
Expand Down

0 comments on commit 696451d

Please sign in to comment.