From 1463c571cfe547cf7e17b42b81a8ec95ba7f0ff5 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 2 Apr 2021 14:13:28 +0200 Subject: [PATCH] Microoptimization --- src/Type/ObjectType.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index e019ba542f..84533aac67 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -984,14 +984,9 @@ public function getClassReflection(): ?ClassReflection */ public function getAncestorWithClassName(string $className): ?TypeWithClassName { - $broker = Broker::getInstance(); - if (!$broker->hasClass($className)) { - return null; - } - $theirReflection = $broker->getClass($className); $description = $this->describeCache(); - if (isset(self::$ancestors[$description][$theirReflection->getName()])) { - return self::$ancestors[$description][$theirReflection->getName()]; + if (isset(self::$ancestors[$description][$className])) { + return self::$ancestors[$description][$className]; } $thisReflection = $this->getClassReflection(); @@ -999,14 +994,20 @@ public function getAncestorWithClassName(string $className): ?TypeWithClassName return null; } + $broker = Broker::getInstance(); + if (!$broker->hasClass($className)) { + return null; + } + $theirReflection = $broker->getClass($className); + if ($theirReflection->getName() === $thisReflection->getName()) { - return self::$ancestors[$description][$theirReflection->getName()] = $this; + return self::$ancestors[$description][$className] = $this; } foreach ($this->getInterfaces() as $interface) { $ancestor = $interface->getAncestorWithClassName($className); if ($ancestor !== null) { - return self::$ancestors[$description][$theirReflection->getName()] = $ancestor; + return self::$ancestors[$description][$className] = $ancestor; } } @@ -1014,7 +1015,7 @@ public function getAncestorWithClassName(string $className): ?TypeWithClassName if ($parent !== null) { $ancestor = $parent->getAncestorWithClassName($className); if ($ancestor !== null) { - return self::$ancestors[$description][$theirReflection->getName()] = $ancestor; + return self::$ancestors[$description][$className] = $ancestor; } }