Direct instantiations of VirtualFileKotlinClass are replaced by access to caching service
This commit is contained in:
@@ -46,7 +46,7 @@ public class CliVirtualFileFinder extends VirtualFileKotlinClassFinder implement
|
||||
|
||||
//NOTE: copied with some changes from CoreJavaFileManager
|
||||
@Nullable
|
||||
private static VirtualFile findFileInRoot(@NotNull String qName, @NotNull VirtualFile root) {
|
||||
private VirtualFile findFileInRoot(@NotNull String qName, @NotNull VirtualFile root) {
|
||||
String pathRest = qName;
|
||||
VirtualFile cur = root;
|
||||
|
||||
@@ -70,7 +70,7 @@ public class CliVirtualFileFinder extends VirtualFileKotlinClassFinder implement
|
||||
return null;
|
||||
}
|
||||
//NOTE: currently we use VirtualFileFinder to find Kotlin binaries only
|
||||
if (KotlinClassHeader.read(new VirtualFileKotlinClass(vFile)) != null) {
|
||||
if (KotlinClassHeader.read(createKotlinClass(vFile)) != null) {
|
||||
return vFile;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-1
@@ -17,16 +17,34 @@
|
||||
package org.jetbrains.jet.lang.resolve.kotlin;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.SLRUCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
public abstract class VirtualFileKotlinClassFinder implements VirtualFileFinder {
|
||||
|
||||
// This cache must be small: we only query the same file a few times in a row (from different places)
|
||||
private final SLRUCache<VirtualFile, KotlinJvmBinaryClass> cache = new SLRUCache<VirtualFile, KotlinJvmBinaryClass>(2, 2) {
|
||||
@NotNull
|
||||
@Override
|
||||
public KotlinJvmBinaryClass createValue(VirtualFile virtualFile) {
|
||||
return new VirtualFileKotlinClass(virtualFile);
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KotlinJvmBinaryClass findKotlinClass(@NotNull FqName fqName) {
|
||||
VirtualFile file = findVirtualFile(fqName);
|
||||
return file == null ? null : new VirtualFileKotlinClass(file);
|
||||
return file == null ? null : createKotlinClass(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public KotlinJvmBinaryClass createKotlinClass(@NotNull VirtualFile file) {
|
||||
synchronized (cache) {
|
||||
return cache.get(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user