You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/10/14 16:05:46 UTC
groovy git commit: Improve the performance of the new highlighter for
groovy console
Repository: groovy
Updated Branches:
refs/heads/master 788d230ed -> aacecde4e
Improve the performance of the new highlighter for groovy console
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/aacecde4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/aacecde4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/aacecde4
Branch: refs/heads/master
Commit: aacecde4e388b61c4a4a54abce0057f22e1de733
Parents: 788d230
Author: Daniel Sun <su...@apache.org>
Authored: Mon Oct 15 00:05:19 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Mon Oct 15 00:05:38 2018 +0800
----------------------------------------------------------------------
.../groovy/ui/text/SmartDocumentFilter.java | 35 ++++++++++++++++++--
1 file changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/aacecde4/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java b/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java
index d666d5f..64fb81e 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java
@@ -39,6 +39,8 @@ import java.awt.Color;
import java.io.IOException;
import java.io.StringReader;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import static org.apache.groovy.parser.antlr4.GroovyLexer.ABSTRACT;
import static org.apache.groovy.parser.antlr4.GroovyLexer.AS;
@@ -165,6 +167,8 @@ public class SmartDocumentFilter extends DocumentFilter {
return string;
}
+ private List<Token> latestTokenList = Collections.emptyList();
+
private void parseDocument() throws BadLocationException {
GroovyLangLexer lexer;
try {
@@ -174,10 +178,10 @@ public class SmartDocumentFilter extends DocumentFilter {
return;
}
- CommonTokenStream tokens = new CommonTokenStream(lexer);
+ CommonTokenStream tokenStream = new CommonTokenStream(lexer);
try {
- tokens.fill();
+ tokenStream.fill();
} catch (LexerNoViableAltException | GroovySyntaxError e) {
// ignore
return;
@@ -186,7 +190,30 @@ public class SmartDocumentFilter extends DocumentFilter {
return;
}
- for (Token token : tokens.getTokens()) {
+ List<Token> tokenList = tokenStream.getTokens();
+
+ boolean toCompareTokens = true;
+ int latestTokenListSize = latestTokenList.size();
+
+ for (int i = 0, n = tokenList.size(); i < n; i++) {
+ Token token = tokenList.get(i);
+
+ // rendering is very time consuming! try to avoid rendering
+ if (toCompareTokens) {
+ if (i < latestTokenListSize) {
+ Token latestToken = latestTokenList.get(i);
+
+ if (token.getStartIndex() == latestToken.getStartIndex()
+ && token.getStopIndex() == latestToken.getStopIndex()
+ && token.getType() == latestToken.getType()) {
+
+ continue;
+ }
+ }
+
+ toCompareTokens = false;
+ }
+
if (token instanceof CommonToken) {
CommonToken commonToken = (CommonToken) token;
// System.out.println(commonToken.toString(lexer));
@@ -215,6 +242,8 @@ public class SmartDocumentFilter extends DocumentFilter {
System.out.println("Unexpected token: " + token.toString());
}
}
+
+ this.latestTokenList = tokenList;
}
private Style findStyleByTokenType(int tokenType) {