Skip to content

Commit

Permalink
do not strongly hold tree to avoid leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim.Mossienko authored and Maxim.Mossienko committed Jan 25, 2011
1 parent ef13dce commit 0460fe9
Showing 1 changed file with 6 additions and 3 deletions.
Expand Up @@ -66,16 +66,19 @@ public static XmlEntityDecl getCachedEntity(PsiFile file, String name) {
return cachedValue != null ? cachedValue.getValue():null;
}

public static void cacheParticularEntity(PsiFile file, final XmlEntityDecl decl) {
public static void cacheParticularEntity(PsiFile file, XmlEntityDecl decl) {
synchronized(PsiLock.LOCK) {
final Map<String, CachedValue<XmlEntityDecl>> cachingMap = getCachingMap(file);
final String name = decl.getName();
if (cachingMap.containsKey(name)) return;
final SmartPsiElementPointer declPointer = SmartPointerManager.getInstance(file.getProject()).createSmartPsiElementPointer(decl);

cachingMap.put(
name, CachedValuesManager.getManager(file.getProject()).createCachedValue(new CachedValueProvider<XmlEntityDecl>() {
public Result<XmlEntityDecl> compute() {
if (decl.isValid() && name.equals(decl.getName()))
return new Result<XmlEntityDecl>(decl,decl);
PsiElement declElement = declPointer.getElement();
if (declElement instanceof XmlEntityDecl && declElement.isValid() && name.equals(((XmlEntityDecl)declElement).getName()))
return new Result<XmlEntityDecl>((XmlEntityDecl)declElement, declElement);
cachingMap.put(name,null);
return new Result<XmlEntityDecl>(null,null);
}
Expand Down

0 comments on commit 0460fe9

Please sign in to comment.