diff Implab/Formats/Json/JsonScanner.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/JsonScanner.cs	Thu Oct 05 09:24:49 2017 +0300
+++ b/Implab/Formats/Json/JsonScanner.cs	Tue Nov 21 14:57:58 2017 +0300
@@ -10,8 +10,8 @@
     /// Сканнер (лексер), разбивающий поток символов на токены JSON.
     /// </summary>
     public abstract class JsonScanner : Disposable {
-        readonly InputScanner<JsonGrammar.TokenType> m_jsonContext = JsonGrammar.CreateJsonExpressionScanner();
-        readonly InputScanner<JsonGrammar.TokenType> m_stringContext = JsonGrammar.CreateStringExpressionScanner();
+        readonly FastInputScanner<JsonGrammar.TokenType> m_jsonContext = JsonGrammar.CreateJsonExpressionScanner();
+        readonly FastInputScanner<JsonGrammar.TokenType> m_stringContext = JsonGrammar.CreateStringExpressionScanner();
 
         readonly char[] m_unescapeBuf = new char[4];
         readonly char[] m_buffer;
@@ -25,7 +25,7 @@
             m_length = length;
         }
 
-        bool ReadChunk(InputScanner<JsonGrammar.TokenType> scanner, out JsonGrammar.TokenType tokenType) {
+        bool ReadChunk(FastInputScanner<JsonGrammar.TokenType> scanner, out JsonGrammar.TokenType tokenType) {
             scanner.ResetState();
 
             while(scanner.Scan(m_buffer, m_pos, m_length)) {
@@ -71,7 +71,7 @@
             return true;
         }
 
-        bool ReadStringChunk(InputScanner<JsonGrammar.TokenType> scanner, out JsonGrammar.TokenType tokenType) {
+        bool ReadStringChunk(FastInputScanner<JsonGrammar.TokenType> scanner, out JsonGrammar.TokenType tokenType) {
             scanner.ResetState();
 
             while (scanner.Scan(m_buffer, m_pos, m_length)) {
@@ -107,7 +107,7 @@
 
             // scanner stops as scannerPos
             if (!scanner.IsFinal)
-                throw new ParserException($"Unexpected character '{m_buffer[scannerPos + 1]}'");
+                throw new ParserException($"Unexpected character '{m_buffer[scannerPos]}'");
 
             if (scannerPos != m_pos) {
                 m_tokenBuilder.Append(m_buffer, m_pos, scannerPos - m_pos);