diff Implab/Formats/Json/JsonGrammar.cs @ 236:302ca905c19e v2

JsonReader optimizations
author cin
date Tue, 21 Nov 2017 14:57:58 +0300
parents 3e26338eb977
children
line wrap: on
line diff
--- a/Implab/Formats/Json/JsonGrammar.cs	Thu Oct 05 09:24:49 2017 +0300
+++ b/Implab/Formats/Json/JsonGrammar.cs	Tue Nov 21 14:57:58 2017 +0300
@@ -31,8 +31,8 @@
             get { return _instance.Value; }
         }
 
-        readonly InputScanner<TokenType> m_jsonExpression;
-        readonly InputScanner<TokenType> m_stringExpression;
+        readonly FastInputScanner<TokenType> m_jsonExpression;
+        readonly FastInputScanner<TokenType> m_stringExpression;
         readonly CharAlphabet m_defaultAlphabet = new CharAlphabet();
 
         public CharAlphabet DefaultAlphabet { get { return m_defaultAlphabet; } }
@@ -87,15 +87,15 @@
                 .Or(unescaped.Closure().Tag(TokenType.UnescapedChar));
                     
 
-            m_jsonExpression = BuildScanner(jsonExpression);
-            m_stringExpression = BuildScanner(jsonStringExpression);
+            m_jsonExpression = BuildFastScanner(jsonExpression);
+            m_stringExpression = BuildFastScanner(jsonStringExpression);
         }
 
-        public static InputScanner<TokenType> CreateJsonExpressionScanner() {
+        public static FastInputScanner<TokenType> CreateJsonExpressionScanner() {
             return Instance.m_jsonExpression.Clone();
         }
 
-        public static InputScanner<TokenType> CreateStringExpressionScanner() {
+        public static FastInputScanner<TokenType> CreateStringExpressionScanner() {
             return Instance.m_stringExpression.Clone();
         }
 
@@ -109,7 +109,7 @@
             return SymbolToken(Enumerable.Range(start, stop - start + 1).Select(x => (char)x));
         }
 
-        public InputScanner<TokenType> BuildScanner(Token regexp) {
+        public FastInputScanner<TokenType> BuildFastScanner(Token regexp) {
             var dfa = new RegularDFA<char, TokenType>(AlphabetBuilder);
 
             var visitor = new RegularExpressionVisitor<TokenType>(dfa);
@@ -122,12 +122,12 @@
             var ab = new CharAlphabet();
             var optimal = dfa.Optimize(ab);
 
-            return new InputScanner<TokenType>(
+            return new FastInputScanner<TokenType>(
                 optimal.CreateTransitionTable(),
                 optimal.CreateFinalStateTable(),
                 NormalizeTags(optimal.CreateTagTable()),
                 optimal.InitialState,
-                ab.CreateCharMap()
+                ab.GetTranslationMap()
             );
         }