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:
parent
2cafa432e3
commit
fc3af1ecfe
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue