From cd5b53db93d99b402ae09ba9968236a7a3c626ce Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 29 Jul 2014 11:01:20 +0200 Subject: [PATCH] RootIndex: cache non-existent packages (IDEA-127942) --- .../intellij/openapi/roots/impl/RootIndex.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java index 165a77b411af..eb04fb6c103e 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java @@ -25,13 +25,16 @@ import com.intellij.openapi.roots.*; import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.LowMemoryWatcher; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.util.CollectionQuery; +import com.intellij.util.EmptyQuery; import com.intellij.util.Query; +import com.intellij.util.containers.ConcurrentHashSet; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import gnu.trove.TObjectIntHashMap; @@ -62,11 +65,20 @@ public class RootIndex { }; private final Map> myDirectoriesByPackageNameCache = ContainerUtil.newConcurrentMap(); + private final Set myNonExistentPackages = new ConcurrentHashSet(); private final InfoCache myInfoCache; private final List> myRootTypes = ContainerUtil.newArrayList(); private final TObjectIntHashMap> myRootTypeId = new TObjectIntHashMap>(); @NotNull private final Project myProject; private volatile Map myOrderEntries; + @SuppressWarnings("UnusedDeclaration") + private final LowMemoryWatcher myLowMemoryWatcher = LowMemoryWatcher.register(new Runnable() { + @Override + public void run() { + myNonExistentPackages.clear(); + } + }); + // made public for Upsource public RootIndex(@NotNull Project project, @NotNull InfoCache cache) { @@ -321,6 +333,8 @@ public class RootIndex { public Query getDirectoriesByPackageName(@NotNull final String packageName, final boolean includeLibrarySources) { List result = myDirectoriesByPackageNameCache.get(packageName); if (result == null) { + if (myNonExistentPackages.contains(packageName)) return EmptyQuery.getEmptyQuery(); + result = ContainerUtil.newSmartList(); if (StringUtil.isNotEmpty(packageName) && !StringUtil.startsWithChar(packageName, '.')) { @@ -348,6 +362,8 @@ public class RootIndex { if (!result.isEmpty()) { myDirectoriesByPackageNameCache.put(packageName, result); + } else { + myNonExistentPackages.add(packageName); } }