From d962b00bb55b09bc5487ed0f5b7d51c0049edec2 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Wed, 2 Mar 2016 15:59:57 +0300 Subject: [PATCH] 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. --- .../vcs-impl/src/com/intellij/openapi/vcs/FilePathImpl.java | 4 +++- .../vcs-impl/src/com/intellij/openapi/vcs/LocalFilePath.java | 4 +++- .../vcs-impl/src/com/intellij/openapi/vcs/RemoteFilePath.java | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/FilePathImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/FilePathImpl.java index 4089cea7ec7f..6600676b9f20 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/FilePathImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/FilePathImpl.java @@ -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 diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/LocalFilePath.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/LocalFilePath.java index 10ac108b4491..4de1b44a1896 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/LocalFilePath.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/LocalFilePath.java @@ -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 diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/RemoteFilePath.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/RemoteFilePath.java index da15800bfe04..d74634638490 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/RemoteFilePath.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/RemoteFilePath.java @@ -37,10 +37,12 @@ public class RemoteFilePath implements FilePath { private static final TObjectHashingStrategy 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