vcs: Refactored "FilePath" implementations not to create new "File" instances on each "getIOFile()" call - reuse same "File" instance created in constructor instead

Otherwise frequent "FilePath.getIOFile()" calls could lead to performance issues. For instance, there are snapshots with slow "Change.isMoved() or Change.isRenamed()" -> "Change.cacheRenameOrMove()" -> "Change.revisionPathsSame()" -> "LocalFilePath.getIOFile()" method calls.
This commit is contained in:
Konstantin Kolosovsky
2016-03-02 16:17:50 +03:00
parent c9ad69b66b
commit d962b00bb5
3 changed files with 9 additions and 3 deletions
@@ -42,10 +42,12 @@ import java.nio.charset.Charset;
@Deprecated
public class FilePathImpl implements FilePath {
@NotNull private final String myPath;
@NotNull private final File myIOFile;
private final boolean myIsDirectory;
public FilePathImpl(@NotNull String path, boolean isDirectory) {
myPath = FileUtil.toCanonicalPath(path);
myIOFile = new File(myPath);
myIsDirectory = isDirectory;
}
public FilePathImpl(@NotNull VirtualFile file) {
@@ -120,7 +122,7 @@ public class FilePathImpl implements FilePath {
@Override
@NotNull
public File getIOFile() {
return new File(myPath);
return myIOFile;
}
@NotNull
@@ -35,10 +35,12 @@ import java.nio.charset.Charset;
public class LocalFilePath implements FilePath {
@NotNull private final String myPath;
@NotNull private final File myIOFile;
private final boolean myIsDirectory;
public LocalFilePath(@NotNull String path, boolean isDirectory) {
myPath = FileUtil.toCanonicalPath(path);
myIOFile = new File(myPath);
myIsDirectory = isDirectory;
}
@@ -110,7 +112,7 @@ public class LocalFilePath implements FilePath {
@Override
@NotNull
public File getIOFile() {
return new File(myPath);
return myIOFile;
}
@NotNull
@@ -37,10 +37,12 @@ public class RemoteFilePath implements FilePath {
private static final TObjectHashingStrategy<String> CASE_SENSITIVE_STRATEGY = FilePathHashingStrategy.create(true);
@NotNull private final String myPath;
@NotNull private final File myIOFile;
private final boolean myIsDirectory;
public RemoteFilePath(@NotNull String path, boolean isDirectory) {
myPath = path;
myIOFile = new File(myPath);
myIsDirectory = isDirectory;
}
@@ -59,7 +61,7 @@ public class RemoteFilePath implements FilePath {
@NotNull
@Override
public File getIOFile() {
return new File(myPath);
return myIOFile;
}
@NotNull