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:
Todd Lang 2018-06-05 13:08:30 -04:00 committed by Steve Sanderson
parent c5c1b375ec
commit 1e866f7672
1 changed files with 14 additions and 3 deletions

View File

@ -1,4 +1,4 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// <copyright file="SimpleJson.cs" company="The Outercurve Foundation">
// Copyright (c) 2011, The Outercurve Foundation.
//
@ -926,8 +926,19 @@ namespace SimpleJson
static void EatWhitespace(char[] json, ref int index)
{
for (; index < json.Length; index++)
if (" \t\n\r\b\f".IndexOf(json[index]) == -1) break;
for (; index < json.Length; index++) {
switch (json[index]) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\b':
case '\f':
break;
default:
return;
}
}
}
static int LookAhead(char[] json, int index)