Skip to content

Commit

Permalink
Token - inline $other->getPrototype() to speedup equals()
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and keradus committed Nov 28, 2018
1 parent 8bf3abe commit 1aecb36
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Tokenizer/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,21 @@ public function clearChanged()
*/
public function equals($other, $caseSensitive = true)
{
$otherPrototype = $other instanceof self ? $other->getPrototype() : $other;
if ($other instanceof self) {
// Inlined getPrototype() on this very hot path.
// We access the private properties of $other directly to save function call overhead.
// This is only possible because $other is of the same class as `self`.
if (!$other->isArray) {
$otherPrototype = $other->content;
} else {
$otherPrototype = [
$other->id,
$other->content,
];
}
} else {
$otherPrototype = $other;
}

if ($this->isArray !== \is_array($otherPrototype)) {
return false;
Expand Down

0 comments on commit 1aecb36

Please sign in to comment.