Skip to content

Commit

Permalink
simpliffy
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Oct 14, 2018
1 parent 8433be7 commit c7fd16d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Tokenizer/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,41 +159,43 @@ public function equals($other, $caseSensitive = true)
if ($other instanceof self) {
// inlined getPrototype() on this very hot path
if (!$other->isArray) {
$other = $other->content;
$otherPrototype = $other->content;
} else {
$other = [
$otherPrototype = [
$other->id,
$other->content,
];
}
} else {
$otherPrototype = $other;
}

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

if (!$this->isArray) {
return $this->content === $other;
return $this->content === $otherPrototype;
}

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

if (array_key_exists(1, $other)) {
if (array_key_exists(1, $otherPrototype)) {
if ($caseSensitive) {
if ($this->content !== $other[1]) {
if ($this->content !== $otherPrototype[1]) {
return false;
}
} elseif (0 !== strcasecmp($this->content, $other[1])) {
} elseif (0 !== strcasecmp($this->content, $otherPrototype[1])) {
return false;
}
}

// detect unknown keys
unset($other[0], $other[1]);
unset($otherPrototype[0], $otherPrototype[1]);

return empty($other);
return empty($otherPrototype);
}

/**
Expand Down

0 comments on commit c7fd16d

Please sign in to comment.