From ec2186745e80eee8c29ac7822307c1044d2e2f65 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 20 May 2015 22:08:29 +0200 Subject: [PATCH] faster RootIndex.getPackageName (IDEA-140431) --- .../openapi/roots/impl/RootIndex.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) 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 50a7e625757c..21f4b9462bf9 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 @@ -54,13 +54,8 @@ public class RootIndex { }; private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.RootIndex"); - private final MultiMap myPackagePrefixRoots = new MultiMap() { - @NotNull - @Override - protected Collection createCollection() { - return ContainerUtil.newLinkedHashSet(); - } - }; + private final MultiMap myRootsByPackagePrefix = MultiMap.create(); + private final Map myPackagePrefixByRoot = ContainerUtil.newHashMap(); private final Map> myDirectoriesByPackageNameCache = ContainerUtil.newConcurrentMap(); private final Set myNonExistentPackages = ContainerUtil.newConcurrentSet(); @@ -90,7 +85,8 @@ public class RootIndex { ? calcDirectoryInfo(root, hierarchy, info) : new Pair(NonProjectDirectoryInfo.IGNORED, null); cacheInfos(root, root, pair.first); - myPackagePrefixRoots.putValue(pair.second, root); + myRootsByPackagePrefix.putValue(pair.second, root); + myPackagePrefixByRoot.put(root, pair.second); } } @@ -247,7 +243,7 @@ public class RootIndex { public void checkConsistency() { - for (VirtualFile file : myPackagePrefixRoots.values()) { + for (VirtualFile file : myRootsByPackagePrefix.values()) { assert file.exists() : file.getPath() + " does not exist"; } } @@ -344,7 +340,7 @@ public class RootIndex { } } - for (VirtualFile file : myPackagePrefixRoots.get(packageName)) { + for (VirtualFile file : myRootsByPackagePrefix.get(packageName)) { if (file.isDirectory()) { result.add(file); } @@ -376,10 +372,8 @@ public class RootIndex { return null; } - for (final Map.Entry> entry : myPackagePrefixRoots.entrySet()) { - if (entry.getValue().contains(dir)) { - return entry.getKey(); - } + if (myPackagePrefixByRoot.containsKey(dir)) { + return myPackagePrefixByRoot.get(dir); } final VirtualFile parent = dir.getParent(); @@ -392,7 +386,7 @@ public class RootIndex { } @Nullable - protected static String getPackageNameForSubdir(String parentPackageName, @NotNull String subdirName) { + protected static String getPackageNameForSubdir(@Nullable String parentPackageName, @NotNull String subdirName) { if (parentPackageName == null) return null; return parentPackageName.isEmpty() ? subdirName : parentPackageName + "." + subdirName; }