java-topology/defects/doctrine/patch/doctrine-0002-classmetadata-subclasses-set.patch

27 lines
1.2 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UNDF: UNDF-2026-000000051
Fixes doctrine-0002: ClassMetadata::addSubClass in_array dedup.
--- a/src/Doctrine/ORM/Mapping/ClassMetadata.php
+++ b/src/Doctrine/ORM/Mapping/ClassMetadata.php
@@ DEFECT doctrine-0002: ClassMetadata.php:2313 addSubClass()
+ /** @var array<string, true> FIX doctrine-0002: hash set for O(1) subclass dedup */
+ public array $subClassesSet = [];
public function addSubClass(string $className): void
{
- if (is_subclass_of($className, $this->name) && ! in_array($className, $this->subClasses, true)) {
- $this->subClasses[] = $className;
+ // FIX doctrine-0002: replace O(S) in_array scan with O(1) hash check.
+ if (is_subclass_of($className, $this->name) && ! isset($this->subClassesSet[$className])) {
+ $this->subClasses[] = $className;
+ $this->subClassesSet[$className] = true;
}
}
# BEFORE: in_array($className, $this->subClasses) — O(S) per addSubClass call.
# ClassMetadataFactory calls addSubClass in loops over parent hierarchies.
# Total: O(H × S) where H = hierarchy depth, S = subclass count.
# AFTER: isset($this->subClassesSet[$className]) — O(1).
# Triggered by: application startup / metadata cache warming.