From 77254ef597e42b4faf3a11a35b6c8191d9345782 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 14 May 2015 15:54:15 +0300 Subject: [PATCH] [vcs] Don't create FilePath object when not needed Use the given VirtualFile, or just String fileName. --- .../changes/actions/ChangeDiffRequestPresentable.java | 10 +++++----- .../actions/ConflictedDiffRequestPresentable.java | 6 ++---- .../changes/patch/MergedDiffRequestPresentable.java | 8 +++----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequestPresentable.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequestPresentable.java index d5c2d3d3f5d5..6612a705003f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequestPresentable.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ChangeDiffRequestPresentable.java @@ -224,7 +224,7 @@ public class ChangeDiffRequestPresentable implements DiffRequestPresentable { final FileType type = rev.getFile().getFileType(); if (! type.isBinary()) return true; if (FileTypes.UNKNOWN.equals(type)) { - final boolean associatedToText = checkAssociate(myProject, rev.getFile(), context); + final boolean associatedToText = checkAssociate(myProject, rev.getFile().getName(), context); } return true; } @@ -255,17 +255,17 @@ public class ChangeDiffRequestPresentable implements DiffRequestPresentable { return false; } - public static boolean checkAssociate(final Project project, final FilePath file, DiffChainContext context) { - final String pattern = FileUtilRt.getExtension(file.getName()).toLowerCase(); + public static boolean checkAssociate(final Project project, String fileName, DiffChainContext context) { + final String pattern = FileUtilRt.getExtension(fileName).toLowerCase(); if (context.contains(pattern)) return false; int rc = Messages.showOkCancelDialog(project, - VcsBundle.message("diff.unknown.file.type.prompt", file.getName()), + VcsBundle.message("diff.unknown.file.type.prompt", fileName), VcsBundle.message("diff.unknown.file.type.title"), VcsBundle.message("diff.unknown.file.type.associate"), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon()); if (rc == Messages.OK) { - FileType fileType = FileTypeChooser.associateFileType(file.getName()); + FileType fileType = FileTypeChooser.associateFileType(fileName); return fileType != null && !fileType.isBinary(); } else { context.add(pattern); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ConflictedDiffRequestPresentable.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ConflictedDiffRequestPresentable.java index b8dd82b90b46..02cd56ed85a4 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ConflictedDiffRequestPresentable.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/ConflictedDiffRequestPresentable.java @@ -24,7 +24,6 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.ChangesUtil; @@ -59,9 +58,8 @@ public class ConflictedDiffRequestPresentable implements DiffRequestPresentable public MyResult step(DiffChainContext context) { if (myChange.getAfterRevision() == null) return createErrorResult(); FileType type = myChange.getVirtualFile() != null ? myChange.getVirtualFile().getFileType() : null; - FilePathImpl filePath = new FilePathImpl(myFile); - if (filePath.getFileType().isBinary()) { - final boolean nowItIsText = ChangeDiffRequestPresentable.checkAssociate(myProject, filePath, context); + if (myFile.getFileType().isBinary()) { + final boolean nowItIsText = ChangeDiffRequestPresentable.checkAssociate(myProject, myFile.getName(), context); if (! nowItIsText) { return createErrorResult(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MergedDiffRequestPresentable.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MergedDiffRequestPresentable.java index a3ddc2ba450d..dddc8c8f7a97 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MergedDiffRequestPresentable.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MergedDiffRequestPresentable.java @@ -22,7 +22,6 @@ import com.intellij.openapi.diff.SimpleDiffRequest; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Getter; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vcs.FilePathImpl; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.changes.actions.*; import com.intellij.openapi.vfs.VirtualFile; @@ -44,9 +43,8 @@ public class MergedDiffRequestPresentable implements DiffRequestPresentable { } public MyResult step(DiffChainContext context) { - FilePathImpl filePath = new FilePathImpl(myFile); - if (filePath.getFileType().isBinary()) { - final boolean nowItIsText = ChangeDiffRequestPresentable.checkAssociate(myProject, filePath, context); + if (myFile.getFileType().isBinary()) { + final boolean nowItIsText = ChangeDiffRequestPresentable.checkAssociate(myProject, myFile.getName(), context); if (! nowItIsText) { final SimpleDiffRequest request = new SimpleDiffRequest(myProject, null); return new MyResult(request, DiffPresentationReturnValue.removeFromList); @@ -61,7 +59,7 @@ public class MergedDiffRequestPresentable implements DiffRequestPresentable { .create3WayDiffRequest(revisionTexts.getLocal().toString(), revisionTexts.getPatched(), revisionTexts.getBase().toString(), - filePath.getFileType(), myProject, null, null); + myFile.getFileType(), myProject, null, null); request.setWindowTitle(VcsBundle.message("patch.apply.conflict.title", FileUtil.toSystemDependentName(myFile.getPresentableUrl()))); request.setVersionTitles(new String[] {"Current Version", "Base Version", FileUtil.toSystemDependentName(myAfterTitle)}); return new MyResult(request, DiffPresentationReturnValue.useRequest);