From 7ff5544573e910209a53033fc7cc687b17ec3d1d Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Fri, 27 Jul 2012 22:20:23 -0700 Subject: [PATCH] wipe out config lookup in ATNConfigSet when it goes readonly. --- .../antlr/v4/runtime/atn/ATNConfigSet.java | 88 ++++++++++++++++++- .../v4/runtime/atn/ParserATNSimulator.java | 3 - .../antlr/v4/runtime/misc/Array2DHashSet.java | 2 +- 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java index 68396b246..2859bc68a 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java @@ -63,7 +63,7 @@ import java.util.Set; 1 12 1 119 <- max size - 322 set size for SLL parser java.* + 322 set size for SLL parser java.* in DFA states: 888 1 411 54 @@ -142,6 +142,91 @@ import java.util.Set; 1 9 1 2 + javalr, java.* all atnconfigsets; max size = 322, num sets = 269088 + + 114186 1 <-- optimize + 35712 6 + 28081 78 + 15252 54 + 14171 56 + 13159 12 + 11810 88 + 6873 86 + 6158 80 + 5169 4 + 3773 118 + 2350 16 + 1002 112 + 915 28 + 898 44 + 734 2 + 632 62 + 575 8 + 566 59 + 474 20 + 388 84 + 343 48 + 333 55 + 328 47 + 311 41 + 306 38 + 277 81 + 263 79 + 255 66 + 245 90 + 245 87 + 234 50 + 224 10 + 220 60 + 194 64 + 186 32 + 184 82 + 150 18 + 125 7 + 121 132 + 116 30 + 103 51 + 95 114 + 84 36 + 82 40 + 78 22 + 77 89 + 55 9 + 53 174 + 48 152 + 44 67 + 44 5 + 42 115 + 41 58 + 38 122 + 37 134 + 34 13 + 34 116 + 29 45 + 29 3 + 29 24 + 27 144 + 26 146 + 25 91 + 24 113 + 20 27 + ... + + number with 1-9 elements: + + 114186 1 + 35712 6 + 5169 4 + 734 2 + 575 8 + 125 7 + 55 9 + 44 5 + 29 3 + + Can cover 60% of sizes with size up to 6 + Can cover 44% of sizes with size up to 4 + Can cover 42% of sizes with size up to 1 */ public class ATNConfigSet implements Set { /* @@ -366,6 +451,7 @@ public class ATNConfigSet implements Set { public void setReadonly(boolean readonly) { this.readonly = readonly; + configLookup.clear(); } @Override diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java index 822c1d318..78b413a8b 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -651,9 +651,6 @@ public class ParserATNSimulator extends ATNSimulator { } if ( reach.size()==0 ) return null; - -// reach.setConflictingAlts(getConflictingAlts(reach, false)); -// return reach; } diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java index c92f86f52..375b992c6 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/Array2DHashSet.java @@ -270,7 +270,7 @@ public class Array2DHashSet implements Set { @Override public void clear() { - buckets = (T[][])new Object[buckets.length][]; + buckets = (T[][])new Object[INITAL_CAPACITY][]; n = 0; }