From ba71108e8b91f9c52d67599e7cde314bb3e55586 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sat, 18 Jan 2014 17:03:08 +0400 Subject: [PATCH] [vcs] Don't wrap FilePath creation into read action There is no point in this read action, but it takes the lock => may slow down if the utility method is used during a large VCS process (even if taken atomically). VCS requires file content rarely, so the only benefit from this read was in the situation, if a VirtualFile gets created when we've already went to createForDeletedFile (and similar situations). However, it is not a big deal, especially since VirtualFile is refreshed inside the FilePathImpl. --- .../peer/impl/VcsContextFactoryImpl.java | 49 +++++-------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/peer/impl/VcsContextFactoryImpl.java b/platform/vcs-impl/src/com/intellij/peer/impl/VcsContextFactoryImpl.java index 4787744f7ce6..ab6b69250ce8 100644 --- a/platform/vcs-impl/src/com/intellij/peer/impl/VcsContextFactoryImpl.java +++ b/platform/vcs-impl/src/com/intellij/peer/impl/VcsContextFactoryImpl.java @@ -16,9 +16,7 @@ package com.intellij.peer.impl; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vcs.actions.VcsContext; @@ -46,41 +44,24 @@ public class VcsContextFactoryImpl implements VcsContextFactory { } public FilePath createFilePathOn(@NotNull final VirtualFile virtualFile) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - public FilePath compute() { - return new FilePathImpl(virtualFile); - } - }); + return new FilePathImpl(virtualFile); } public FilePath createFilePathOn(final File file) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - public FilePath compute() { - return FilePathImpl.create(file); - } - }); + return FilePathImpl.create(file); } public FilePath createFilePathOn(final File file, final NotNullFunction detector) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - public FilePath compute() { - VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file); - if (virtualFile != null) { - // detector information (loaded here lazily) is not needed - we have real file - return FilePathImpl.create(file); - } - - return FilePathImpl.create(file, detector.fun(file).booleanValue()); - } - }); + VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file); + if (virtualFile != null) { + // detector information (loaded here lazily) is not needed - we have real file + return FilePathImpl.create(file); + } + return FilePathImpl.create(file, detector.fun(file).booleanValue()); } public FilePath createFilePathOn(final File file, final boolean isDirectory) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - public FilePath compute() { - return FilePathImpl.create(file, isDirectory); - } - }); + return FilePathImpl.create(file, isDirectory); } @NotNull @@ -89,19 +70,11 @@ public class VcsContextFactoryImpl implements VcsContextFactory { } public FilePath createFilePathOnDeleted(final File file, final boolean isDirectory) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - public FilePath compute() { - return FilePathImpl.createForDeletedFile(file, isDirectory); - } - }); + return FilePathImpl.createForDeletedFile(file, isDirectory); } public FilePath createFilePathOn(final VirtualFile parent, final String name) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - public FilePath compute() { - return new FilePathImpl(parent, name, false); - } - }); + return new FilePathImpl(parent, name, false); } public LocalChangeList createLocalChangeList(Project project, @NotNull final String name) {