From 7a9ea508544b1eb2885dabe57dbfe1adde054d90 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 9 Jul 2012 19:10:24 +0400 Subject: [PATCH] [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. --- .../com/intellij/openapi/vfs/newvfs/events/VFileEvent.java | 3 +++ .../git4idea/src/git4idea/repo/GitRepositoryUpdater.java | 6 +++--- .../git4idea/src/git4idea/repo/GitUntrackedFilesHolder.java | 5 ++--- plugins/git4idea/src/git4idea/roots/GitRootScanner.java | 5 ++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileEvent.java index 909bd42284ca..3e931a588d7d 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileEvent.java @@ -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(); diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryUpdater.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryUpdater.java index 5bf34489e979..b95fb692d950 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryUpdater.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryUpdater.java @@ -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)) { diff --git a/plugins/git4idea/src/git4idea/repo/GitUntrackedFilesHolder.java b/plugins/git4idea/src/git4idea/repo/GitUntrackedFilesHolder.java index 389c20aafa2b..33a701d154e0 100644 --- a/plugins/git4idea/src/git4idea/repo/GitUntrackedFilesHolder.java +++ b/plugins/git4idea/src/git4idea/repo/GitUntrackedFilesHolder.java @@ -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; } diff --git a/plugins/git4idea/src/git4idea/roots/GitRootScanner.java b/plugins/git4idea/src/git4idea/roots/GitRootScanner.java index 02cebd2fce56..37e15beea9d2 100644 --- a/plugins/git4idea/src/git4idea/roots/GitRootScanner.java +++ b/plugins/git4idea/src/git4idea/roots/GitRootScanner.java @@ -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 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(); } }