[git] Optimize listening of VFS events: don't use VirtualFile#getFile(), use getPath() and getName() instead.

getFile() calls findChild for VFileCreateEvent, which may result in performance problems as in IDEA-87656.
This commit is contained in:
Kirill Likhodedov
2012-07-09 19:13:07 +04:00
parent b4660bdf4d
commit 7a9ea50854
4 changed files with 10 additions and 9 deletions
@@ -46,6 +46,9 @@ public abstract class VFileEvent {
/**
* Returns the VirtualFile which this event belongs to.
* In some cases it may be null - it is not guaranteed that there is such file.
*
* NB: Use this method with caution, because {@link com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent#getFile()} needs
* {@link VirtualFile#findChild(String)} which may be a performance leak.
*/
@Nullable
public abstract VirtualFile getFile();
@@ -112,11 +112,11 @@ final class GitRepositoryUpdater implements Disposable, BulkFileListener {
boolean rebaseFileChanged = false;
boolean mergeFileChanged = false;
for (VFileEvent event : events) {
final VirtualFile file = event.getFile();
if (file == null) {
String filePath = event.getPath();
if (filePath == null) {
continue;
}
String filePath = GitFileUtils.stripFileProtocolPrefix(file.getPath());
filePath = GitFileUtils.stripFileProtocolPrefix(filePath);
if (myRepositoryFiles.isConfigFile(filePath)) {
configChanged = true;
} else if (myRepositoryFiles.isHeadFile(filePath)) {
@@ -227,11 +227,10 @@ public class GitUntrackedFilesHolder implements Disposable, BulkFileListener {
if (allChanged) {
break;
}
VirtualFile file = event.getFile();
if (file == null) {
String path = event.getPath();
if (path == null) {
continue;
}
String path = file.getPath();
if (totalRefreshNeeded(path)) {
allChanged = true;
}
@@ -25,7 +25,6 @@ import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsListener;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
@@ -79,8 +78,8 @@ public class GitRootScanner implements BulkFileListener, ModuleRootListener, Dis
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
for (VFileEvent event : events) {
VirtualFile file = event.getFile();
if (file != null && file.getName().equalsIgnoreCase(GitUtil.DOT_GIT) && file.isDirectory()) {
String filePath = event.getPath();
if (filePath != null && filePath.toLowerCase().endsWith(GitUtil.DOT_GIT)) {
scanIfReady();
}
}