From 9347aa5829a03f2f494c7d87f49597425de62321 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 3 Mar 2017 17:40:59 +0300 Subject: [PATCH] Use soft ref to list instead of list of soft refs to cleanup code * See https://github.com/JetBrains/intellij-community/commit/2b5487ff1a457c519be8f6bb9775c85ffc03c4cf#commitcomment-21133757 --- .../python/psi/resolve/PythonPathCache.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/resolve/PythonPathCache.java b/python/src/com/jetbrains/python/psi/resolve/PythonPathCache.java index 695471955132..918973790175 100644 --- a/python/src/com/jetbrains/python/psi/resolve/PythonPathCache.java +++ b/python/src/com/jetbrains/python/psi/resolve/PythonPathCache.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; * @author yole */ public abstract class PythonPathCache { - private final Map>> myCache = ContainerUtil.newConcurrentMap(); + private final Map>> myCache = ContainerUtil.newConcurrentMap(); private final Map> myQNameCache = ContainerUtil.newConcurrentMap(); public void clearCache() { @@ -46,21 +46,21 @@ public abstract class PythonPathCache { */ @Nullable public List get(@NotNull final QualifiedName qualifiedName) { - final List> references = myCache.get(qualifiedName); + final SoftReference> references = myCache.get(qualifiedName); if (references == null) { return null; } - final List result = references.stream().map(r -> r.get()).collect(Collectors.toList()); - if (result.stream().anyMatch(o -> o == null || ! o.isValid())) { - // Null in list means SoftReference has been collected meaning cache is not valid + final List elements = references.get(); + if(elements != null && ! elements.stream().allMatch(PsiElement::isValid)) { + // At least one element is invalid return null; } - return result; + return elements; } public void put(QualifiedName qualifiedName, List results) { if (results != null) { - myCache.put(qualifiedName, new ArrayList<>(results.stream().map(e -> new SoftReference<>(e)).collect(Collectors.toList()))); + myCache.put(qualifiedName, new SoftReference<>(results)); } }