comparison Implab/Formats/Json/JsonReader.cs @ 236:302ca905c19e v2

JsonReader optimizations
author cin
date Tue, 21 Nov 2017 14:57:58 +0300
parents 3e26338eb977
children
comparison
equal deleted inserted replaced
235:b49969a7043c 236:302ca905c19e
46 m_elementContext = context; 46 m_elementContext = context;
47 } 47 }
48 48
49 public bool Move(JsonTokenType token) { 49 public bool Move(JsonTokenType token) {
50 var next = m_dfa[m_state, (int)token]; 50 var next = m_dfa[m_state, (int)token];
51 if (next == AutomatonConst.UNREACHABLE_STATE) 51 if (next == AutomatonConst.UnreachableState)
52 return false; 52 return false;
53 m_state = next; 53 m_state = next;
54 return true; 54 return true;
55 } 55 }
56 56
114 readonly JsonScanner m_scanner; 114 readonly JsonScanner m_scanner;
115 // json starts from the value context and may content even a single literal 115 // json starts from the value context and may content even a single literal
116 MemberContext m_memberContext = MemberContext.MemberValue; 116 MemberContext m_memberContext = MemberContext.MemberValue;
117 117
118 JsonElementType m_elementType; 118 JsonElementType m_elementType;
119 object m_elementValue; 119 string m_elementValue;
120 string m_memberName = String.Empty; 120 string m_memberName = String.Empty;
121 121
122 Stack<ParserContext> m_stack = new Stack<ParserContext>(); 122 Stack<ParserContext> m_stack = new Stack<ParserContext>();
123 ParserContext m_context = _jsonContext; 123 ParserContext m_context = _jsonContext;
124 124
150 } 150 }
151 151
152 /// <summary> 152 /// <summary>
153 /// Значение элемента. Только для элементов типа <see cref="JsonElementType.Value"/>, для остальных <c>null</c> 153 /// Значение элемента. Только для элементов типа <see cref="JsonElementType.Value"/>, для остальных <c>null</c>
154 /// </summary> 154 /// </summary>
155 public object ElementValue { 155 public string ElementValue {
156 get { return m_elementValue; } 156 get { return m_elementValue; }
157 } 157 }
158 158
159 /// <summary> 159 /// <summary>
160 /// Читает слеюудущий объект из потока 160 /// Читает слеюудущий объект из потока
211 m_elementType = JsonElementType.Value; 211 m_elementType = JsonElementType.Value;
212 m_elementValue = tokenValue; 212 m_elementValue = tokenValue;
213 return true; 213 return true;
214 case JsonTokenType.Number: 214 case JsonTokenType.Number:
215 m_elementType = JsonElementType.Value; 215 m_elementType = JsonElementType.Value;
216 m_elementValue = double.Parse(tokenValue, CultureInfo.InvariantCulture); 216 m_elementValue = tokenValue;
217 return true; 217 return true;
218 case JsonTokenType.Literal: 218 case JsonTokenType.Literal:
219 m_elementType = JsonElementType.Value; 219 m_elementType = JsonElementType.Value;
220 m_elementValue = ParseLiteral(tokenValue); 220 m_elementValue = tokenValue == "null" ? null : tokenValue;
221 return true; 221 return true;
222 case JsonTokenType.NameSeparator: 222 case JsonTokenType.NameSeparator:
223 m_memberContext = MemberContext.MemberValue; 223 m_memberContext = MemberContext.MemberValue;
224 break; 224 break;
225 case JsonTokenType.ValueSeparator: 225 case JsonTokenType.ValueSeparator: