From 1aecb367c0ce68b7a74b2b5a59c69bc9d7f6854d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 14 Oct 2018 11:23:41 +0000 Subject: [PATCH] Token - inline $other->getPrototype() to speedup equals() --- src/Tokenizer/Token.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Tokenizer/Token.php b/src/Tokenizer/Token.php index 1fdb8601ccc..0ae3fdc1ca7 100644 --- a/src/Tokenizer/Token.php +++ b/src/Tokenizer/Token.php @@ -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;