Skip to content

Commit

Permalink
Cache some more
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 2, 2021
1 parent dbe08a6 commit 626f72a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class ObjectType implements TypeWithClassName, SubtractableType
/** @var array<string, array<string, array<string, UnresolvedPropertyPrototypeReflection>>> */
private static array $properties = [];

/** @var array<string, array<string, self>> */
private static array $ancestors = [];

public function __construct(
string $className,
?Type $subtractedType = null,
Expand Down Expand Up @@ -986,27 +989,32 @@ public function getAncestorWithClassName(string $className): ?TypeWithClassName
return null;
}
$theirReflection = $broker->getClass($className);
$description = $this->describeCache();
if (isset(self::$ancestors[$description][$theirReflection->getName()])) {
return self::$ancestors[$description][$theirReflection->getName()];
}

$thisReflection = $this->getClassReflection();
if ($thisReflection === null) {
return null;
}

if ($theirReflection->getName() === $thisReflection->getName()) {
return $this;
return self::$ancestors[$description][$theirReflection->getName()] = $this;
}

foreach ($this->getInterfaces() as $interface) {
$ancestor = $interface->getAncestorWithClassName($className);
if ($ancestor !== null) {
return $ancestor;
return self::$ancestors[$description][$theirReflection->getName()] = $ancestor;
}
}

$parent = $this->getParent();
if ($parent !== null) {
$ancestor = $parent->getAncestorWithClassName($className);
if ($ancestor !== null) {
return $ancestor;
return self::$ancestors[$description][$theirReflection->getName()] = $ancestor;
}
}

Expand Down

0 comments on commit 626f72a

Please sign in to comment.