PY-70247 Cache the stub-based computation of ScopeUtilCore.getScopeOwner()

GitOrigin-RevId: 5eca49ca75c7bb6b1bccd2dc3a7d4cd5f3009725
This commit is contained in:
Petr
2025-08-17 20:35:28 +02:00
committed by intellij-monorepo-bot
parent cf177b24d9
commit 9198c0fb92

View File

@@ -33,6 +33,11 @@ public final class ScopeUtilCore {
final PsiElement context = element.getContext();
return context instanceof AstScopeOwner ? (AstScopeOwner)context : getScopeOwner(context);
}
return CachedValuesManager.getCachedValue(element, () -> CachedValueProvider.Result
.create(calculateScopeOwner(element), PsiModificationTracker.MODIFICATION_COUNT));
}
private static @Nullable AstScopeOwner calculateScopeOwner(@Nullable PsiElement element) {
if (element instanceof StubBasedPsiElement<?> stubBasedElement) {
final StubElement<?> stub = stubBasedElement.getStub();
if (stub != null) {
@@ -52,11 +57,6 @@ public final class ScopeUtilCore {
return firstOwner;
}
}
return CachedValuesManager.getCachedValue(element, () -> CachedValueProvider.Result
.create(calculateScopeOwnerByAST(element), PsiModificationTracker.MODIFICATION_COUNT));
}
private static @Nullable AstScopeOwner calculateScopeOwnerByAST(@Nullable PsiElement element) {
final AstScopeOwner firstOwner = getParentOfType(element, AstScopeOwner.class);
if (firstOwner == null) {
return null;