Skip to content

Commit

Permalink
Parser: Replace === with == where safe for performance reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
halaxa committed Feb 5, 2022
1 parent eeb2051 commit 8a2771a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ public function getIterator()
$iteratorLevel = count($jsonPointerPath);
}
$tokenType = $tokenTypes[$token[0]];
if (0 === ($tokenType & $expectedType)) {
if (0 == ($tokenType & $expectedType)) {
$this->error('Unexpected symbol', $token);
}
$isValue = ($tokenType | 23) === 23; // 23 = self::ANY_VALUE
$isValue = ($tokenType | 23) == 23; // 23 = self::ANY_VALUE
if ( ! $inObject && $isValue && $currentLevel < $iteratorLevel) {
$currentPathChanged = ! $this->hasSingleJsonPointer;
$currentPath[$currentLevel] = isset($currentPath[$currentLevel]) ? (string) (1 + (int) $currentPath[$currentLevel]) : '0';
Expand All @@ -126,16 +126,16 @@ public function getIterator()
}
if (
(
$jsonPointerPath === $currentPath
|| $jsonPointerPath === $currentPathWildcard
$jsonPointerPath == $currentPath
|| $jsonPointerPath == $currentPathWildcard
)
&& (
$currentLevel > $iteratorLevel
|| (
! $objectKeyExpected
&& (
($currentLevel === $iteratorLevel && $isValue)
|| ($currentLevel + 1 === $iteratorLevel && ($tokenType | 3) === 3) // 3 = self::SCALAR_VALUE
($currentLevel == $iteratorLevel && $isValue)
|| ($currentLevel + 1 == $iteratorLevel && ($tokenType | 3) == 3) // 3 = self::SCALAR_VALUE
)
)
)
Expand All @@ -148,7 +148,7 @@ public function getIterator()
if ($objectKeyExpected) {
$objectKeyExpected = false;
$expectedType = 128; // 128 = self::COLON
if ($currentLevel === $iteratorLevel) {
if ($currentLevel == $iteratorLevel) {
$key = $token;
} elseif ($currentLevel < $iteratorLevel) {
$key = $token;
Expand Down Expand Up @@ -201,7 +201,7 @@ public function getIterator()
// no break
case ']':
--$currentLevel;
$inObject = $stack[$currentLevel] === '{';
$inObject = $stack[$currentLevel] == '{';
// no break
default:
if ($inObject) {
Expand All @@ -219,7 +219,7 @@ public function getIterator()
if ( ! $valueResult->isOk()) {
$this->error($valueResult->getErrorMessage(), $token);
}
if ($iteratorStruct === '[') {
if ($iteratorStruct == '[') {
yield $valueResult->getValue();
} else {
$keyResult = $this->jsonDecoder->decode($key);
Expand All @@ -231,11 +231,11 @@ public function getIterator()
}
unset($valueResult);
}
if ($jsonPointerPath === $currentPath || $jsonPointerPath === $currentPathWildcard) {
if ($jsonPointerPath == $currentPath || $jsonPointerPath == $currentPathWildcard) {
if ( ! in_array($this->matchedJsonPointer, $pointersFound, true)) {
$pointersFound[] = $this->matchedJsonPointer;
}
} elseif (count($pointersFound) === count($this->jsonPointers)) {
} elseif (count($pointersFound) == count($this->jsonPointers)) {
$subtreeEnded = true;
break;
}
Expand Down

0 comments on commit 8a2771a

Please sign in to comment.