Remove explicit static constructors

Explicit static cctors cause the C# compiler to not mark types as
beforefieldinit, which means the JIT will add checks to each static
method and instance constructors of the type to make sure that the
static constructor was previously called. This can be avoided by
removing explicit static constructors and initializing static fields
inline.
This commit is contained in:
Justin Van Patten 2017-03-12 16:29:09 -07:00 committed by Chris R
parent 2cafa432e3
commit fc3af1ecfe
1 changed files with 23 additions and 21 deletions

View File

@ -10,7 +10,7 @@ namespace Microsoft.Net.Http.Headers
{
internal static class HttpRuleParser
{
private static readonly bool[] TokenChars;
private static readonly bool[] TokenChars = CreateTokenChars();
private const int MaxNestedCount = 5;
private static readonly string[] DateFormats = new string[] {
// "r", // RFC 1123, required output format but too strict for input
@ -43,36 +43,38 @@ namespace Microsoft.Net.Http.Headers
// iso-8859-1, Western European (ISO)
internal static readonly Encoding DefaultHttpEncoding = Encoding.GetEncoding("iso-8859-1");
static HttpRuleParser()
private static bool[] CreateTokenChars()
{
// token = 1*<any CHAR except CTLs or separators>
// CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
TokenChars = new bool[128]; // everything is false
var tokenChars = new bool[128]; // everything is false
for (int i = 33; i < 127; i++) // skip Space (32) & DEL (127)
{
TokenChars[i] = true;
tokenChars[i] = true;
}
// remove separators: these are not valid token characters
TokenChars[(byte)'('] = false;
TokenChars[(byte)')'] = false;
TokenChars[(byte)'<'] = false;
TokenChars[(byte)'>'] = false;
TokenChars[(byte)'@'] = false;
TokenChars[(byte)','] = false;
TokenChars[(byte)';'] = false;
TokenChars[(byte)':'] = false;
TokenChars[(byte)'\\'] = false;
TokenChars[(byte)'"'] = false;
TokenChars[(byte)'/'] = false;
TokenChars[(byte)'['] = false;
TokenChars[(byte)']'] = false;
TokenChars[(byte)'?'] = false;
TokenChars[(byte)'='] = false;
TokenChars[(byte)'{'] = false;
TokenChars[(byte)'}'] = false;
tokenChars[(byte)'('] = false;
tokenChars[(byte)')'] = false;
tokenChars[(byte)'<'] = false;
tokenChars[(byte)'>'] = false;
tokenChars[(byte)'@'] = false;
tokenChars[(byte)','] = false;
tokenChars[(byte)';'] = false;
tokenChars[(byte)':'] = false;
tokenChars[(byte)'\\'] = false;
tokenChars[(byte)'"'] = false;
tokenChars[(byte)'/'] = false;
tokenChars[(byte)'['] = false;
tokenChars[(byte)']'] = false;
tokenChars[(byte)'?'] = false;
tokenChars[(byte)'='] = false;
tokenChars[(byte)'{'] = false;
tokenChars[(byte)'}'] = false;
return tokenChars;
}
internal static bool IsTokenChar(char character)