From 8285e19d323df6cb01555c5d10f5d1614ebc71e9 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Fri, 19 Apr 2013 18:53:01 +0400 Subject: [PATCH] Added class ancestors cache --- .../python/psi/impl/PyClassImpl.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java index f5079648c79f..f3f047fd53b4 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyClassImpl.java @@ -52,6 +52,24 @@ public class PyClassImpl extends PyPresentableElementImpl implement private volatile Map myPropertyCache; + private class CachedAncestorsProvider implements CachedValueProvider> { + @Nullable private TypeEvalContext myCachedContext; + + @Nullable + @Override + public Result> compute() { + final TypeEvalContext context = myCachedContext != null ? myCachedContext : TypeEvalContext.fastStubOnly(null); + final List ancestorTypes = isNewStyleClass() ? getMROAncestorTypes(context) : getOldStyleAncestorTypes(context); + return Result.create(ancestorTypes, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); + } + + private void setTypeEvalContext(@Nullable TypeEvalContext cachedContext) { + myCachedContext = cachedContext; + } + } + + private final CachedAncestorsProvider myCachedAncestorsProvider = new CachedAncestorsProvider(); + @Override public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) { return new PyClassTypeImpl(this, true); @@ -1063,7 +1081,19 @@ public class PyClassImpl extends PyPresentableElementImpl implement @NotNull @Override public List getAncestorTypes(@NotNull TypeEvalContext context) { - return isNewStyleClass() ? getMROAncestorTypes(context) : getOldStyleAncestorTypes(context); + return calculateAncestorTypes(context); + } + + @NotNull + private List calculateAncestorTypes(@NotNull TypeEvalContext context) { + myCachedAncestorsProvider.setTypeEvalContext(context); + try { + // TODO: Return different cached copies depending on the type eval context parameters + return CachedValuesManager.getManager(getProject()).getCachedValue(this, myCachedAncestorsProvider); + } + finally { + myCachedAncestorsProvider.setTypeEvalContext(null); + } } @NotNull