mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
speed optimisation
This commit is contained in:
@@ -16,11 +16,15 @@
|
||||
package com.intellij.compiler.impl.javaCompiler.api;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* User: cdr
|
||||
@@ -31,12 +35,33 @@ class JavaIoFile extends SimpleJavaFileObject {
|
||||
@Nullable
|
||||
private final String myEncoding;
|
||||
|
||||
JavaIoFile(File file, Kind kind, @Nullable String encoding) {
|
||||
super(file.toURI(), kind);
|
||||
JavaIoFile(@NotNull File file, @NotNull Kind kind, @Nullable String encoding) {
|
||||
super(convertToURI(file.getPath()), kind);
|
||||
myFile = file;
|
||||
myEncoding = encoding;
|
||||
}
|
||||
|
||||
// File.toURI() asks for File.isDirectory which is too expensive
|
||||
@NotNull
|
||||
private static URI convertToURI(@NotNull String path) {
|
||||
if (File.separatorChar != '/') {
|
||||
path = path.replace(File.separatorChar, '/');
|
||||
}
|
||||
if (!StringUtil.startsWithChar(path, '/')) {
|
||||
path = "/" + path;
|
||||
}
|
||||
|
||||
if (path.startsWith("//")) {
|
||||
path = "//" + path;
|
||||
}
|
||||
try {
|
||||
return new URI("file", null, path, null);
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
|
||||
return FileUtil.loadFile(myFile, myEncoding);
|
||||
|
||||
+2
-1
@@ -123,7 +123,8 @@ class MyFileManager implements StandardJavaFileManager {
|
||||
if (kind == JavaFileObject.Kind.SOURCE && child.getFileSystem() instanceof JarFileSystem) continue; //for some reasdon javac looks for java files inside jar
|
||||
|
||||
// use VFS to read content inside .jar
|
||||
JavaFileObject fileObject = !child.getPath().contains("!/") ? new JavaIoFile(new File(child.getPath()), kind, myEncoding) : new JavaVirtualFile(child, kind);
|
||||
String childPath = child.getPath();
|
||||
JavaFileObject fileObject = !childPath.contains("!/") ? new JavaIoFile(new File(childPath), kind, myEncoding) : new JavaVirtualFile(child, kind);
|
||||
results.add(fileObject);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user