Skip to content

Commit 8ed7156

Browse files
committed
Added cache from previous version of FileTypeMapper
1 parent 256d11b commit 8ed7156

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Type/FileTypeMapper.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class FileTypeMapper
4949
/** @var (false|(callable(): \PHPStan\Analyser\NameScope)|\PHPStan\Analyser\NameScope)[][] */
5050
private array $inProcess = [];
5151

52+
/** @var array<string, ResolvedPhpDocBlock> */
53+
private array $resolvedPhpDocBlockCache = [];
54+
5255
/** @var array<string, bool> */
5356
private array $alreadyProcessedDependentFiles = [];
5457

@@ -83,14 +86,18 @@ public function getResolvedPhpDoc(
8386
}
8487

8588
$nameScopeKey = $this->getNameScopeKey($fileName, $className, $traitName, $functionName);
89+
$phpDocKey = md5(sprintf('%s-%s', $nameScopeKey, $docComment));
90+
if (isset($this->resolvedPhpDocBlockCache[$phpDocKey])) {
91+
return $this->resolvedPhpDocBlockCache[$phpDocKey];
92+
}
8693
$nameScopeMap = [];
8794

8895
if (!isset($this->inProcess[$fileName])) {
8996
$nameScopeMap = $this->getNameScopeMap($fileName);
9097
}
9198

9299
if (isset($nameScopeMap[$nameScopeKey])) {
93-
return $this->createResolvedPhpDocBlock($nameScopeMap[$nameScopeKey], $docComment, $fileName);
100+
return $this->createResolvedPhpDocBlock($phpDocKey, $nameScopeMap[$nameScopeKey], $docComment, $fileName);
94101
}
95102

96103
if (!isset($this->inProcess[$fileName][$nameScopeKey])) { // wrong $fileName due to traits
@@ -107,10 +114,10 @@ public function getResolvedPhpDoc(
107114
$this->inProcess[$fileName][$nameScopeKey] = $resolveCallback();
108115
}
109116

110-
return $this->createResolvedPhpDocBlock($this->inProcess[$fileName][$nameScopeKey], $docComment, $fileName);
117+
return $this->createResolvedPhpDocBlock($phpDocKey, $this->inProcess[$fileName][$nameScopeKey], $docComment, $fileName);
111118
}
112119

113-
private function createResolvedPhpDocBlock(NameScope $nameScope, string $phpDocString, string $fileName): ResolvedPhpDocBlock
120+
private function createResolvedPhpDocBlock(string $phpDocKey, NameScope $nameScope, string $phpDocString, string $fileName): ResolvedPhpDocBlock
114121
{
115122
$phpDocNode = $this->resolvePhpDocStringToDocNode($phpDocString);
116123
$templateTags = $this->phpDocNodeResolver->resolveTemplateTags($phpDocNode, $nameScope);
@@ -140,7 +147,7 @@ private function createResolvedPhpDocBlock(NameScope $nameScope, string $phpDocS
140147
$templateTypeMap = TemplateTypeMap::createEmpty();
141148
}
142149

143-
return ResolvedPhpDocBlock::create(
150+
return $this->resolvedPhpDocBlockCache[$phpDocKey] = ResolvedPhpDocBlock::create(
144151
$phpDocNode,
145152
$phpDocString,
146153
$fileName,

0 commit comments

Comments
 (0)