diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java index 854a29988f6e..2f5485d6deae 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java @@ -35,6 +35,8 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.util.Query; +import com.intellij.util.containers.ConcurrentIntObjectMap; +import com.intellij.util.containers.StripedLockIntObjectConcurrentHashMap; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -122,7 +124,19 @@ public class DirectoryIndexImpl extends DirectoryIndex { private RootIndex getRootIndex() { RootIndex rootIndex = myRootIndex; if (rootIndex == null) { - myRootIndex = rootIndex = new RootIndex(myProject); + myRootIndex = rootIndex = new RootIndex(myProject, new RootIndex.InfoCache() { + // Upsource can't use int-mapping because different files may have the same id there + private final ConcurrentIntObjectMap myInfoCache = new StripedLockIntObjectConcurrentHashMap(); + @Override + public void cacheInfo(@NotNull VirtualFile dir, @NotNull DirectoryInfo info) { + myInfoCache.put(((NewVirtualFile)dir).getId(), info); + } + + @Override + public DirectoryInfo getCachedInfo(@NotNull VirtualFile dir) { + return myInfoCache.get(((NewVirtualFile)dir).getId()); + } + }); } return rootIndex; } 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 8e58a6b3c78c..41f1d823041a 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 @@ -61,15 +61,16 @@ public class RootIndex extends DirectoryIndex { }; private final Map> myDirectoriesByPackageNameCache = ContainerUtil.newConcurrentMap(); - private final Map myInfoCache = ContainerUtil.newConcurrentMap(); + 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; // made public for Upsource - public RootIndex(@NotNull Project project) { + public RootIndex(@NotNull Project project, InfoCache cache) { myProject = project; + myInfoCache = cache; final RootInfo info = buildRootInfo(project); Set allRoots = info.getAllRoots(); @@ -265,7 +266,7 @@ public class RootIndex extends DirectoryIndex { return null; } if (!dir.isDirectory()) { - DirectoryInfo info = myInfoCache.get(dir); + DirectoryInfo info = myInfoCache.getCachedInfo(dir); return info == NULL_INFO ? null : info; } @@ -274,7 +275,7 @@ public class RootIndex extends DirectoryIndex { if (++count > 1000) { throw new IllegalStateException("Possible loop in tree, started at " + dir.getName()); } - DirectoryInfo info = myInfoCache.get(root); + DirectoryInfo info = myInfoCache.getCachedInfo(root); if (info != null) { if (!dir.equals(root)) { cacheInfos(dir, root, info); @@ -293,7 +294,7 @@ public class RootIndex extends DirectoryIndex { @Nullable private DirectoryInfo cacheInfos(VirtualFile dir, @Nullable VirtualFile stopAt, @Nullable DirectoryInfo info) { while (dir != null) { - myInfoCache.put(dir, info == null ? NULL_INFO : info); + myInfoCache.cacheInfo(dir, info == null ? NULL_INFO : info); if (dir.equals(stopAt)) { break; } @@ -590,4 +591,9 @@ public class RootIndex extends DirectoryIndex { return Pair.create(directoryInfo, packagePrefix); } + + public interface InfoCache { + @Nullable DirectoryInfo getCachedInfo(@NotNull VirtualFile dir); + void cacheInfo(@NotNull VirtualFile dir, @NotNull DirectoryInfo info); + } } \ No newline at end of file