groovy git commit: GROOVY-8793: Add a switch to clear lexer cache

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

groovy git commit: GROOVY-8793: Add a switch to clear lexer cache

Daniel.Sun
Repository: groovy
Updated Branches:
  refs/heads/master 4523d0446 -> eb08b5e17


GROOVY-8793: Add a switch to clear lexer cache


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/eb08b5e1
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/eb08b5e1
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/eb08b5e1

Branch: refs/heads/master
Commit: eb08b5e17218d081fc3f7e4cd80877c0567af85b
Parents: 4523d04
Author: Daniel Sun <[hidden email]>
Authored: Sat Sep 15 04:52:30 2018 +0800
Committer: Daniel Sun <[hidden email]>
Committed: Sat Sep 15 04:52:30 2018 +0800

----------------------------------------------------------------------
 .../org/apache/groovy/parser/antlr4/internal/AtnManager.java  | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/eb08b5e1/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/internal/AtnManager.java
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/internal/AtnManager.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/internal/AtnManager.java
index a8752bc..686ec14 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/internal/AtnManager.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/internal/AtnManager.java
@@ -22,6 +22,7 @@ import org.antlr.v4.runtime.atn.ATN;
 import org.apache.groovy.parser.antlr4.GroovyLangLexer;
 import org.apache.groovy.parser.antlr4.GroovyLangParser;
 import org.apache.groovy.util.Maps;
+import org.apache.groovy.util.SystemUtil;
 
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicLong;
@@ -36,11 +37,13 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 public class AtnManager {
     public static final ReentrantReadWriteLock RRWL = new ReentrantReadWriteLock(true);
     private static final String DFA_CACHE_THRESHOLD_OPT = "groovy.antlr4.cache.threshold";
+    private static final String GROOVY_CLEAR_LEXER_DFA_CACHE = "groovy.clear.lexer.dfa.cache";
     private static final int DEFAULT_DFA_CACHE_THRESHOLD = 64;
     private static final int MIN_DFA_CACHE_THRESHOLD = 32;
     private static final int DFA_CACHE_THRESHOLD;
     private final Class ownerClass;
     private final ATN atn;
+    private static final boolean TO_CLEAR_LEXER_DFA_CACHE;
     private static final Map<Class, AtnWrapper> ATN_MAP = Maps.of(
             GroovyLangLexer.class, new AtnWrapper(GroovyLangLexer._ATN),
             GroovyLangParser.class, new AtnWrapper(GroovyLangParser._ATN)
@@ -59,11 +62,13 @@ public class AtnManager {
         }
 
         DFA_CACHE_THRESHOLD = t;
+
+        TO_CLEAR_LEXER_DFA_CACHE = SystemUtil.getBooleanSafe(GROOVY_CLEAR_LEXER_DFA_CACHE);
     }
 
     public AtnManager(GroovyLangLexer lexer) {
         this.ownerClass = lexer.getClass();
-        this.atn = GroovyLangLexer._ATN; //getAtnWrapper(this.ownerClass).checkAndClear();
+        this.atn = TO_CLEAR_LEXER_DFA_CACHE ? getAtnWrapper(this.ownerClass).checkAndClear() : GroovyLangLexer._ATN;
     }
 
     public AtnManager(GroovyLangParser parser) {

Daniel Sun
Apache Groovy committer

Blog: http://blog.sunlan.me
Twitter: @daniel_sun