Skip to content

Commit

Permalink
inline $other->getPrototype() to speedup equals()
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Oct 15, 2018
1 parent 818e26c commit 1d0400a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Tokenizer/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,19 @@ 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
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 1d0400a

Please sign in to comment.