diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32FsCache.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32FsCache.java index 7c72bcd4dc74..476ac27df681 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32FsCache.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32FsCache.java @@ -23,7 +23,10 @@ import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; import java.util.ArrayList; +import java.util.List; import java.util.Map; /** @@ -31,10 +34,21 @@ import java.util.Map; */ class Win32FsCache { private final IdeaWin32 myKernel = IdeaWin32.getInstance(); - private final Map myCache = new THashMap(); + private Reference> myCache; void clearCache() { - myCache.clear(); + myCache = null; + } + + @NotNull + private Map getMap() { + Reference> cache = myCache; + Map map = cache == null ? null : cache.get(); + if (map == null) { + map = new THashMap(); + myCache = new SoftReference>(map); + } + return map; } @NotNull @@ -44,16 +58,17 @@ class Win32FsCache { return ArrayUtil.EMPTY_STRING_ARRAY; } - ArrayList names = new ArrayList(fileInfo.length); + List names = new ArrayList(fileInfo.length); + Map map = getMap(); for (FileInfo info : fileInfo) { if (info.name.equals(".")) { - myCache.put(absolutePath, info); + map.put(absolutePath, info); continue; } if (info.name.equals("..")) { continue; } - myCache.put(absolutePath + "/" + info.name, info); + map.put(absolutePath + "/" + info.name, info); names.add(info.name); } @@ -63,13 +78,14 @@ class Win32FsCache { @Nullable FileInfo getInfo(@NotNull VirtualFile file) { String path = file.getPath(); - FileInfo info = myCache.get(path); + Map map = getMap(); + FileInfo info = map.get(path); if (info == null) { info = myKernel.getInfo(path.replace('/', '\\')); if (info == null) { return null; } - myCache.put(path, info); + map.put(path, info); } return info; }