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) {
6464 return Runnables .doNothing ();
6565 }
6666
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+
6774 return () -> {
6875 if (documentManager .isDocumentBlockedByPsi (document )) {
6976 documentManager .doPostponedOperationsAndUnblockDocument (document );
70- String newText = document .getText ();
71- if (!newText .equals (origText )) {
72- return ;
73- }
7477 }
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+
7587 document .setText (text );
7688 };
7789 }
You can’t perform that action at this time.
0 commit comments