diff: do not call read action to access to local read-only document
authorAleksey Pivovarov <Aleksey.Pivovarov@jetbrains.com>
Tue, 18 Feb 2014 14:15:08 +0000 (18:15 +0400)
committerAleksey Pivovarov <Aleksey.Pivovarov@jetbrains.com>
Fri, 21 Feb 2014 08:38:02 +0000 (12:38 +0400)
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java

index 7528495aa35ca47c4dfa69e1b5028911a50ab431..5b44749b8a82a7e4d4e5f2c3c2efc0454a8ea2e0 100644 (file)
@@ -112,63 +112,64 @@ public class FragmentedDiffRequestFromChange {
       return myOldDocument;
     }
 
-    public void execute(final Change change, final FilePath filePath, final SLRUMap<Pair<Long, String>, List<BeforeAfter<TextRange>>> cache,
+    public void execute(final Change change,
+                        final FilePath filePath,
+                        final SLRUMap<Pair<Long, String>, List<BeforeAfter<TextRange>>> 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<BeforeAfter<TextRange>> cached = cache.get(new Pair<Long, String>(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<BeforeAfter<TextRange>> cached = cache.get(new Pair<Long, String>(myDocument.getModificationStamp(), convertedPath));
+            if (cached != null) {
+              myRanges = cached;
+              return;
             }
-
-            if (myDocument == null) {
-              myDocument = documentFromRevision(change.getAfterRevision());
-              final List<BeforeAfter<TextRange>> cached = cache.get(new Pair<Long, String>(-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<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
-            myRanges = new ArrayList<BeforeAfter<TextRange>>(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<TextRange>(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<Long, String>(myDocument.getModificationStamp(), convertedPath), new ArrayList<BeforeAfter<TextRange>>(myRanges));
           }
-          catch (VcsException e) {
-            myException = e;
+        }
+
+        if (myDocument == null) {
+          myDocument = documentFromRevision(change.getAfterRevision());
+          final List<BeforeAfter<TextRange>> cached = cache.get(new Pair<Long, String>(-1L, convertedPath));
+          if (cached != null) {
+            myRanges = cached;
+            return;
           }
-          catch (FilesTooBigForDiffException e) {
-            myException = new VcsException(e);
+        }
+
+        ComparisonPolicy comparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy();
+        if (comparisonPolicy == null) {
+          comparisonPolicy = ComparisonPolicy.DEFAULT;
+        }
+        final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy);
+        final ArrayList<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
+        myRanges = new ArrayList<BeforeAfter<TextRange>>(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<TextRange>(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<Long, String>(myDocument.getModificationStamp(), convertedPath), new ArrayList<BeforeAfter<TextRange>>(myRanges));
+      }
+      catch (VcsException e) {
+        myException = e;
+      }
+      catch (FilesTooBigForDiffException e) {
+        myException = new VcsException(e);
+      }
     }
     
     private int correctRangeEnd(final int end, final Document document) {