Skip to content

Commit

Permalink
minor #4047 Token - inline $other->getPrototype() to speedup equals()…
Browse files Browse the repository at this point in the history
… (staabm, keradus)

This PR was merged into the 2.12 branch.

Discussion
----------

Token - inline $other->getPrototype() to speedup equals()

as measured in #4026 we try to speedup equals() by inlinening the $this->getPrototype() call.

~~also we use FQCN for native functions, because equals() is called a lot.~~

this speedsup the process by 4-5%.

see https://blackfire.io/profiles/compare/f4eefae8-6d09-4ab4-a833-f828d74a7b52/graph
![image](https://user-images.githubusercontent.com/120441/46916011-d6d2c400-cfb4-11e8-89e1-ec64e77477f1.png)

Commits
-------

1aecb36 Token - inline $other->getPrototype() to speedup equals()
  • Loading branch information
keradus committed Nov 28, 2018
2 parents 6b0562e + 1aecb36 commit e7bb262
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Tokenizer/Token.php
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 e7bb262

Please sign in to comment.