Refactoring SimpleJson.EatWhiteSpace
-Replacing arbitrary length IndexOf call with unrolled switch statement -Reduces deserialization runtime on ~310KB test data from 13s to 5s.
This commit is contained in:
parent
c5c1b375ec
commit
1e866f7672
|
|
@ -1,4 +1,4 @@
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// <copyright file="SimpleJson.cs" company="The Outercurve Foundation">
|
// <copyright file="SimpleJson.cs" company="The Outercurve Foundation">
|
||||||
// Copyright (c) 2011, The Outercurve Foundation.
|
// Copyright (c) 2011, The Outercurve Foundation.
|
||||||
//
|
//
|
||||||
|
|
@ -926,8 +926,19 @@ namespace SimpleJson
|
||||||
|
|
||||||
static void EatWhitespace(char[] json, ref int index)
|
static void EatWhitespace(char[] json, ref int index)
|
||||||
{
|
{
|
||||||
for (; index < json.Length; index++)
|
for (; index < json.Length; index++) {
|
||||||
if (" \t\n\r\b\f".IndexOf(json[index]) == -1) break;
|
switch (json[index]) {
|
||||||
|
case ' ':
|
||||||
|
case '\t':
|
||||||
|
case '\n':
|
||||||
|
case '\r':
|
||||||
|
case '\b':
|
||||||
|
case '\f':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LookAhead(char[] json, int index)
|
static int LookAhead(char[] json, int index)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue