Skip to content

Commit 741d418

Browse files
committed
minor symfony#61721 [TypeInfo] improve BuiltinType::isIdentifiedBy() method performance (landure)
This PR was merged into the 7.3 branch. Discussion ---------- [TypeInfo] improve BuiltinType::isIdentifiedBy() method performance Improve `isIdentifiedBy` method performance by replacing unnecessary `TypeIdentifier` backed enum instantiation by an identity test between a string identifier and its value. | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no <!-- if yes, also update src/**/CHANGELOG.md --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md --> | Issues | Fix symfony#61720 | License | MIT <!-- 🛠️ Replace this text with a concise explanation of your change: - What it does and why it's needed - A simple example of how it works (include PHP, YAML, etc.) - If it modifies existing behavior, include a before/after comparison Contributor guidelines: - ✅ Add tests and ensure they pass - 🐞 Bug fixes must target the **lowest maintained** branch where they apply https://symfony.com/releases#maintained-symfony-branches - ✨ New features and deprecations must target the **feature** branch and must add an entry to the changelog file of the patched component: https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - 🔒 Do not break backward compatibility: https://symfony.com/bc --> Commits ------- caf9dc8 [TypeInfo] simplify identifier comparison in isIdentifiedBy method
2 parents 84c65cb + caf9dc8 commit 741d418

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/Symfony/Component/TypeInfo/Type/BuiltinType.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,7 @@ public function getTypeIdentifier(): TypeIdentifier
4141
public function isIdentifiedBy(TypeIdentifier|string ...$identifiers): bool
4242
{
4343
foreach ($identifiers as $identifier) {
44-
if (\is_string($identifier)) {
45-
try {
46-
$identifier = TypeIdentifier::from($identifier);
47-
} catch (\ValueError) {
48-
continue;
49-
}
50-
}
51-
52-
if ($identifier === $this->typeIdentifier) {
44+
if ($identifier === $this->typeIdentifier || $identifier === $this->typeIdentifier->value) {
5345
return true;
5446
}
5547
}

0 commit comments

Comments
 (0)