File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
idea_plugin/src/main/java/com/google/googlejavaformat/intellij Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -64,14 +64,26 @@ public boolean supports(@NotNull PsiFile file) {
64
64
return Runnables .doNothing ();
65
65
}
66
66
67
+ /* pointless to change document text if it hasn't changed, plus this can interfere with
68
+ e.g. GoogleJavaFormattingService's output, i.e. it can overwrite the results from the main
69
+ formatter. */
70
+ if (text .equals (origText )) {
71
+ return Runnables .doNothing ();
72
+ }
73
+
67
74
return () -> {
68
75
if (documentManager .isDocumentBlockedByPsi (document )) {
69
76
documentManager .doPostponedOperationsAndUnblockDocument (document );
70
- String newText = document .getText ();
71
- if (!newText .equals (origText )) {
72
- return ;
73
- }
74
77
}
78
+
79
+ /* similarly to above, don't overwrite new document text if it has changed - we use
80
+ getCharsSequence() as we should have `writeAction()` (which I think means effectively a
81
+ write-lock) and it saves calling getText(), which apparently is expensive. */
82
+ CharSequence newText = document .getCharsSequence ();
83
+ if (CharSequence .compare (origText , newText ) != 0 ) {
84
+ return ;
85
+ }
86
+
75
87
document .setText (text );
76
88
};
77
89
}
You can’t perform that action at this time.
0 commit comments