From b285dea60fe09fdbcff5099471a322748dc7944c Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Tue, 18 Feb 2014 18:15:08 +0400 Subject: [PATCH] diff: do not call read action to access to local read-only document --- .../FragmentedDiffRequestFromChange.java | 107 +++++++++--------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java index 7528495aa35c..5b44749b8a82 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java @@ -112,63 +112,64 @@ public class FragmentedDiffRequestFromChange { return myOldDocument; } - public void execute(final Change change, final FilePath filePath, final SLRUMap, List>> cache, + public void execute(final Change change, + final FilePath filePath, + final SLRUMap, List>> cache, final LineStatusTrackerManagerI lstManager) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - public void run() { - try { - myDocument = null; - myOldDocument = documentFromRevision(change.getBeforeRevision()); - final String convertedPath = FilePathsHelper.convertPath(filePath); - if (filePath.getVirtualFile() != null) { - myDocument = FileStatus.DELETED.equals(change.getFileStatus()) ? new DocumentImpl("") : - FileDocumentManager.getInstance().getDocument(filePath.getVirtualFile()); - if (myDocument != null) { - final List> cached = cache.get(new Pair(myDocument.getModificationStamp(), convertedPath)); - if (cached != null) { - myRanges = cached; - return; - } - } + try { + myDocument = null; + myOldDocument = documentFromRevision(change.getBeforeRevision()); + final String convertedPath = FilePathsHelper.convertPath(filePath); + if (filePath.getVirtualFile() != null) { + myDocument = FileStatus.DELETED.equals(change.getFileStatus()) + ? new DocumentImpl("") + : FileDocumentManager.getInstance().getDocument(filePath.getVirtualFile()); + if (myDocument != null) { + final List> cached = cache.get(new Pair(myDocument.getModificationStamp(), convertedPath)); + if (cached != null) { + myRanges = cached; + return; } - - if (myDocument == null) { - myDocument = documentFromRevision(change.getAfterRevision()); - final List> cached = cache.get(new Pair(-1L, convertedPath)); - if (cached != null) { - myRanges = cached; - return; - } - } - - ComparisonPolicy comparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy(); - if (comparisonPolicy == null) { - comparisonPolicy = ComparisonPolicy.DEFAULT; - } - final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy); - final ArrayList lineFragments = processor.process(myOldDocument.getText(), myDocument.getText()); - myRanges = new ArrayList>(lineFragments.size()); - for (LineFragment lineFragment : lineFragments) { - if (! lineFragment.isEqual()) { - final TextRange oldRange = lineFragment.getRange(FragmentSide.SIDE1); - final TextRange newRange = lineFragment.getRange(FragmentSide.SIDE2); - myRanges.add(new BeforeAfter(new UnfairTextRange(myOldDocument.getLineNumber(oldRange.getStartOffset()), - myOldDocument.getLineNumber(correctRangeEnd(oldRange.getEndOffset(), myOldDocument))), - new UnfairTextRange(myDocument.getLineNumber(newRange.getStartOffset()), - myDocument.getLineNumber(correctRangeEnd(newRange.getEndOffset(), myDocument))))); - } - } - cache.put(new Pair(myDocument.getModificationStamp(), convertedPath), new ArrayList>(myRanges)); - } - catch (VcsException e) { - myException = e; - } - catch (FilesTooBigForDiffException e) { - myException = new VcsException(e); } } - }); + + if (myDocument == null) { + myDocument = documentFromRevision(change.getAfterRevision()); + final List> cached = cache.get(new Pair(-1L, convertedPath)); + if (cached != null) { + myRanges = cached; + return; + } + } + + ComparisonPolicy comparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy(); + if (comparisonPolicy == null) { + comparisonPolicy = ComparisonPolicy.DEFAULT; + } + final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy); + final ArrayList lineFragments = processor.process(myOldDocument.getText(), myDocument.getText()); + myRanges = new ArrayList>(lineFragments.size()); + for (LineFragment lineFragment : lineFragments) { + if (!lineFragment.isEqual()) { + final TextRange oldRange = lineFragment.getRange(FragmentSide.SIDE1); + final TextRange newRange = lineFragment.getRange(FragmentSide.SIDE2); + myRanges.add(new BeforeAfter(new UnfairTextRange(myOldDocument.getLineNumber(oldRange.getStartOffset()), + myOldDocument.getLineNumber( + correctRangeEnd(oldRange.getEndOffset(), myOldDocument))), + new UnfairTextRange(myDocument.getLineNumber(newRange.getStartOffset()), myDocument + .getLineNumber(correctRangeEnd(newRange.getEndOffset(), myDocument))) + )); + } + } + cache + .put(new Pair(myDocument.getModificationStamp(), convertedPath), new ArrayList>(myRanges)); + } + catch (VcsException e) { + myException = e; + } + catch (FilesTooBigForDiffException e) { + myException = new VcsException(e); + } } private int correctRangeEnd(final int end, final Document document) {