Skip to content

Commit

Permalink
[Performance] [NodeNameResolver] Move loop REGEX_WILDCARD_CHARS on la…
Browse files Browse the repository at this point in the history
…st resort after $resolvedName, $desiredName compare to avoid unnecesary loop when possible (#4996)
  • Loading branch information
samsonasik committed Sep 11, 2023
1 parent 398b650 commit 7b4858b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/NodeNameResolver/NodeNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,17 @@ public function isStringName(string $resolvedName, string $desiredName): bool
return $desiredName === $resolvedName;
}

if (strcasecmp($resolvedName, $desiredName) === 0) {
return true;
}

foreach(self::REGEX_WILDCARD_CHARS as $char) {
if (str_contains($desiredName, $char)) {
throw new ShouldNotHappenException('Matching of regular expressions is no longer supported. Use $this->getName() and compare with e.g. str_ends_with() or str_starts_with() instead.');
}
}

return strcasecmp($resolvedName, $desiredName) === 0;
return false;
}

private function isCallOrIdentifier(Expr|Identifier $node): bool
Expand Down

0 comments on commit 7b4858b

Please sign in to comment.