@@ -68,6 +68,24 @@ public class SimpleCharStream {
6868 String mySqlCommentError ;
6969 boolean mySqlMinusSubstitution ;
7070
71+ // derived from featureConfiguration, refreshed on identity change: the
72+ // configuration is wired before parsing starts and is not mutated mid-parse
73+ private FeatureConfiguration derivedFrom ;
74+ private boolean derivedMySqlDialect ;
75+ private boolean derivedBlankLineSeparator = true ;
76+ private boolean derivedAllowHashLineComments ;
77+
78+ private void refreshDerivedFeatures () {
79+ derivedFrom = featureConfiguration ;
80+ derivedMySqlDialect = featureConfiguration != null
81+ && AbstractJSqlParser .Dialect .MYSQL .name ()
82+ .equals (featureConfiguration .getValue (Feature .dialect ));
83+ derivedBlankLineSeparator = featureConfiguration == null
84+ || featureConfiguration .getAsBoolean (Feature .allowBlankLinesAsStatementSeparator );
85+ derivedAllowHashLineComments = featureConfiguration != null
86+ && featureConfiguration .getAsBoolean (Feature .allowHashLineComments );
87+ }
88+
7189 /**
7290 * Constructor.
7391 */
@@ -201,17 +219,16 @@ public final char BeginToken() throws java.io.IOException {
201219
202220 absoluteTokenBegin = totalCharsRead ;
203221
204- if (c == '#' && featureConfiguration != null
205- && featureConfiguration .getAsBoolean (Feature .allowHashLineComments )) {
222+ if (featureConfiguration != derivedFrom ) {
223+ refreshDerivedFeatures ();
224+ }
225+
226+ if (c == '#' && derivedAllowHashLineComments ) {
206227 buffer [bufpos ] = HASH_SUBSTITUTION ;
207228 c = HASH_SUBSTITUTION ;
208- } else if ((c == '-' || c == '/' || c == '*' ) && featureConfiguration != null
209- && AbstractJSqlParser .Dialect .MYSQL .name ()
210- .equals (featureConfiguration .getValue (Feature .dialect ))) {
229+ } else if ((c == '-' || c == '/' || c == '*' ) && derivedMySqlDialect ) {
211230 c = mySqlCommentBoundary (c );
212- } else if (c == '\n' && featureConfiguration != null
213- && !featureConfiguration
214- .getAsBoolean (Feature .allowBlankLinesAsStatementSeparator )
231+ } else if (c == '\n' && !derivedBlankLineSeparator
215232 && peekCharacters (2 ).equals ("\n \n " )) {
216233 // Blanking the first newline of the run stops ST_SEMICOLON matching "\n\n\n";
217234 // line and column tracking was already updated when the newline was read.
0 commit comments