Mercurial > pub > ImplabNet
comparison Implab/Formats/InputScanner.cs @ 229:5f7a3e1d32b9 v2
JsonXmlReader performance tuning
JsonScanner now operates strings and doesn't
  parses number and literals.
Added SerializationHelpers to common serialize/deserialize operations
| author | cin | 
|---|---|
| date | Tue, 12 Sep 2017 19:07:42 +0300 | 
| parents | 6fa235c5a760 | 
| children | 302ca905c19e | 
   comparison
  equal
  deleted
  inserted
  replaced
| 228:6fa235c5a760 | 229:5f7a3e1d32b9 | 
|---|---|
| 1 using Implab.Automaton; | 1 using Implab.Automaton; | 
| 2 using System; | 2 using System; | 
| 3 using System.Collections.Generic; | 3 using System.Collections.Generic; | 
| 4 using System.Linq; | 4 using System.Linq; | 
| 5 using System.Runtime.CompilerServices; | |
| 5 using System.Text; | 6 using System.Text; | 
| 6 using System.Threading.Tasks; | 7 using System.Threading.Tasks; | 
| 7 | 8 | 
| 8 namespace Implab.Formats { | 9 namespace Implab.Formats { | 
| 9 public class InputScanner<TTag> { | 10 public class InputScanner<TTag> { | 
| 28 m_initialState = initialState; | 29 m_initialState = initialState; | 
| 29 m_alphabet = alphabet; | 30 m_alphabet = alphabet; | 
| 30 } | 31 } | 
| 31 | 32 | 
| 32 public TTag Tag { | 33 public TTag Tag { | 
| 34 [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| 33 get { | 35 get { | 
| 34 return m_tags[m_state]; | 36 return m_tags[m_state]; | 
| 35 } | 37 } | 
| 36 } | 38 } | 
| 37 | 39 | 
| 38 public int Position { | 40 public int Position { | 
| 41 [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| 39 get { | 42 get { | 
| 40 return m_position; | 43 return m_position; | 
| 41 } | 44 } | 
| 42 } | 45 } | 
| 43 | 46 | 
| 44 public bool IsFinal { | 47 public bool IsFinal { | 
| 48 [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| 45 get { | 49 get { | 
| 46 return m_final[m_state]; | 50 return m_final[m_state]; | 
| 47 } | 51 } | 
| 48 } | 52 } | 
| 49 | 53 | 
| 50 public void Reset() { | 54 [MethodImpl(MethodImplOptions.AggressiveInlining)] | 
| 55 public void ResetState() { | |
| 51 m_state = m_initialState; | 56 m_state = m_initialState; | 
| 52 } | 57 } | 
| 53 | 58 | 
| 54 public InputScanner<TTag> Clone() { | 59 public InputScanner<TTag> Clone() { | 
| 55 var clone = new InputScanner<TTag>(m_dfa, m_final, m_tags, m_initialState, m_alphabet); | 60 var clone = new InputScanner<TTag>(m_dfa, m_final, m_tags, m_initialState, m_alphabet); | 
| 56 clone.m_state = m_state; | 61 clone.m_state = m_state; | 
| 57 clone.m_position = m_position; | 62 clone.m_position = m_position; | 
| 58 return clone; | 63 return clone; | 
| 59 } | 64 } | 
| 60 | 65 | 
| 61 public bool Scan(char[] data, int offset, int length) { | 66 //[MethodImpl(MethodImplOptions.AggressiveInlining)] | 
| 62 if (length <= 0) { | 67 public bool Scan(char[] data, int offset, int max) { | 
| 63 m_position = offset; | |
| 64 return false; // EOF | |
| 65 } | |
| 66 | |
| 67 var max = offset + length; | |
| 68 var next = m_state; | 68 var next = m_state; | 
| 69 | 69 | 
| 70 while(offset < max) { | 70 while(offset < max) { | 
| 71 next = m_dfa[next, m_alphabet.Translate(data[offset])]; | 71 next = m_dfa[next, m_alphabet.Translate(data[offset])]; | 
| 72 if (next == AutomatonConst.UNREACHABLE_STATE) { | 72 if (next == AutomatonConst.UNREACHABLE_STATE) { | 
