Merge branch 'anderman/faster-unsafe' into dev

This commit is contained in:
Stephen Halter 2016-01-05 12:33:14 -08:00
commit b1a4e8cd1e
4 changed files with 1385 additions and 1361 deletions

View File

@ -770,7 +770,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override StringValues GetValueFast(string key)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -1384,7 +1384,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override bool TryGetValueFast(string key, out StringValues value)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -2083,7 +2083,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override void SetValueFast(string key, StringValues value)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -2473,7 +2473,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override void AddValueFast(string key, StringValues value)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -3039,7 +3039,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override bool RemoveFast(string key)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -4237,8 +4237,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value)
{
fixed(byte* ptr = keyBytes) { var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB;
switch(keyLength)
fixed (byte* ptr = &keyBytes[keyOffset])
{
var pUB = ptr;
var pUL = (ulong*)pUB;
var pUI = (uint*)pUB;
var pUS = (ushort*)pUB;
switch (keyLength)
{
case 13:
{
@ -4931,7 +4936,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
}
break;
}}
}
}
var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength);
StringValues existing;
Unknown.TryGetValue(key, out existing);
@ -6114,7 +6120,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override StringValues GetValueFast(string key)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -6628,7 +6634,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override bool TryGetValueFast(string key, out StringValues value)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -7211,7 +7217,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override void SetValueFast(string key, StringValues value)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -7546,7 +7552,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override void AddValueFast(string key, StringValues value)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -8025,7 +8031,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
protected override bool RemoveFast(string key)
{
switch(key.Length)
switch (key.Length)
{
case 13:
{
@ -9027,7 +9033,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 1L) != 0))
{
foreach(var value in _CacheControl)
foreach (var value in _CacheControl)
{
if (value != null)
{
@ -9042,8 +9048,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawConnection != null)
{
output.CopyFrom(_rawConnection, 0, _rawConnection.Length);
} else
foreach(var value in _Connection)
}
else
foreach (var value in _Connection)
{
if (value != null)
{
@ -9058,8 +9065,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawDate != null)
{
output.CopyFrom(_rawDate, 0, _rawDate.Length);
} else
foreach(var value in _Date)
}
else
foreach (var value in _Date)
{
if (value != null)
{
@ -9071,7 +9079,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 8L) != 0))
{
foreach(var value in _KeepAlive)
foreach (var value in _KeepAlive)
{
if (value != null)
{
@ -9083,7 +9091,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 16L) != 0))
{
foreach(var value in _Pragma)
foreach (var value in _Pragma)
{
if (value != null)
{
@ -9095,7 +9103,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 32L) != 0))
{
foreach(var value in _Trailer)
foreach (var value in _Trailer)
{
if (value != null)
{
@ -9110,8 +9118,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawTransferEncoding != null)
{
output.CopyFrom(_rawTransferEncoding, 0, _rawTransferEncoding.Length);
} else
foreach(var value in _TransferEncoding)
}
else
foreach (var value in _TransferEncoding)
{
if (value != null)
{
@ -9123,7 +9132,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 128L) != 0))
{
foreach(var value in _Upgrade)
foreach (var value in _Upgrade)
{
if (value != null)
{
@ -9135,7 +9144,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 256L) != 0))
{
foreach(var value in _Via)
foreach (var value in _Via)
{
if (value != null)
{
@ -9147,7 +9156,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 512L) != 0))
{
foreach(var value in _Warning)
foreach (var value in _Warning)
{
if (value != null)
{
@ -9159,7 +9168,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 1024L) != 0))
{
foreach(var value in _Allow)
foreach (var value in _Allow)
{
if (value != null)
{
@ -9174,8 +9183,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawContentLength != null)
{
output.CopyFrom(_rawContentLength, 0, _rawContentLength.Length);
} else
foreach(var value in _ContentLength)
}
else
foreach (var value in _ContentLength)
{
if (value != null)
{
@ -9187,7 +9197,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 4096L) != 0))
{
foreach(var value in _ContentType)
foreach (var value in _ContentType)
{
if (value != null)
{
@ -9199,7 +9209,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 8192L) != 0))
{
foreach(var value in _ContentEncoding)
foreach (var value in _ContentEncoding)
{
if (value != null)
{
@ -9211,7 +9221,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 16384L) != 0))
{
foreach(var value in _ContentLanguage)
foreach (var value in _ContentLanguage)
{
if (value != null)
{
@ -9223,7 +9233,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 32768L) != 0))
{
foreach(var value in _ContentLocation)
foreach (var value in _ContentLocation)
{
if (value != null)
{
@ -9235,7 +9245,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 65536L) != 0))
{
foreach(var value in _ContentMD5)
foreach (var value in _ContentMD5)
{
if (value != null)
{
@ -9247,7 +9257,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 131072L) != 0))
{
foreach(var value in _ContentRange)
foreach (var value in _ContentRange)
{
if (value != null)
{
@ -9259,7 +9269,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 262144L) != 0))
{
foreach(var value in _Expires)
foreach (var value in _Expires)
{
if (value != null)
{
@ -9271,7 +9281,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 524288L) != 0))
{
foreach(var value in _LastModified)
foreach (var value in _LastModified)
{
if (value != null)
{
@ -9283,7 +9293,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 1048576L) != 0))
{
foreach(var value in _AcceptRanges)
foreach (var value in _AcceptRanges)
{
if (value != null)
{
@ -9295,7 +9305,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 2097152L) != 0))
{
foreach(var value in _Age)
foreach (var value in _Age)
{
if (value != null)
{
@ -9307,7 +9317,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 4194304L) != 0))
{
foreach(var value in _ETag)
foreach (var value in _ETag)
{
if (value != null)
{
@ -9319,7 +9329,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 8388608L) != 0))
{
foreach(var value in _Location)
foreach (var value in _Location)
{
if (value != null)
{
@ -9331,7 +9341,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 16777216L) != 0))
{
foreach(var value in _ProxyAutheticate)
foreach (var value in _ProxyAutheticate)
{
if (value != null)
{
@ -9343,7 +9353,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 33554432L) != 0))
{
foreach(var value in _RetryAfter)
foreach (var value in _RetryAfter)
{
if (value != null)
{
@ -9358,8 +9368,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawServer != null)
{
output.CopyFrom(_rawServer, 0, _rawServer.Length);
} else
foreach(var value in _Server)
}
else
foreach (var value in _Server)
{
if (value != null)
{
@ -9371,7 +9382,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 134217728L) != 0))
{
foreach(var value in _SetCookie)
foreach (var value in _SetCookie)
{
if (value != null)
{
@ -9383,7 +9394,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 268435456L) != 0))
{
foreach(var value in _Vary)
foreach (var value in _Vary)
{
if (value != null)
{
@ -9395,7 +9406,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 536870912L) != 0))
{
foreach(var value in _WWWAuthenticate)
foreach (var value in _WWWAuthenticate)
{
if (value != null)
{
@ -9407,7 +9418,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 1073741824L) != 0))
{
foreach(var value in _AccessControlAllowCredentials)
foreach (var value in _AccessControlAllowCredentials)
{
if (value != null)
{
@ -9419,7 +9430,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 2147483648L) != 0))
{
foreach(var value in _AccessControlAllowHeaders)
foreach (var value in _AccessControlAllowHeaders)
{
if (value != null)
{
@ -9431,7 +9442,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 4294967296L) != 0))
{
foreach(var value in _AccessControlAllowMethods)
foreach (var value in _AccessControlAllowMethods)
{
if (value != null)
{
@ -9443,7 +9454,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 8589934592L) != 0))
{
foreach(var value in _AccessControlAllowOrigin)
foreach (var value in _AccessControlAllowOrigin)
{
if (value != null)
{
@ -9455,7 +9466,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 17179869184L) != 0))
{
foreach(var value in _AccessControlExposeHeaders)
foreach (var value in _AccessControlExposeHeaders)
{
if (value != null)
{
@ -9467,7 +9478,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (((_bits & 34359738368L) != 0))
{
foreach(var value in _AccessControlMaxAge)
foreach (var value in _AccessControlMaxAge)
{
if (value != null)
{
@ -9480,8 +9491,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value)
{
fixed(byte* ptr = keyBytes) { var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB;
switch(keyLength)
fixed (byte* ptr = &keyBytes[keyOffset])
{
var pUB = ptr;
var pUL = (ulong*)pUB;
var pUI = (uint*)pUB;
var pUS = (ushort*)pUB;
switch (keyLength)
{
case 13:
{
@ -10063,7 +10079,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
}
break;
}}
}
}
var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength);
StringValues existing;
Unknown.TryGetValue(key, out existing);

View File

@ -175,9 +175,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
}
else if (_block.End - _index >= sizeof(long))
{
fixed (byte* ptr = _block.Array)
fixed (byte* ptr = &_block.Array[_index])
{
return *(long*)(ptr + _index);
return *(long*)(ptr);
}
}
else if (_block.Next == null)
@ -195,15 +195,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
}
long blockLong;
fixed (byte* ptr = _block.Array)
fixed (byte* ptr = &_block.Array[_block.End - sizeof(long)])
{
blockLong = *(long*)(ptr + _block.End - sizeof(long));
blockLong = *(long*)(ptr);
}
long nextLong;
fixed (byte* ptr = _block.Next.Array)
fixed (byte* ptr = &_block.Next.Array[_block.Next.Start])
{
nextLong = *(long*)(ptr + _block.Next.Start);
nextLong = *(long*)(ptr );
}
return (blockLong >> (sizeof(long) - blockBytes) * 8) | (nextLong << (sizeof(long) - nextBytes) * 8);
@ -770,9 +770,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3;
}
fixed (byte* pOutput = block.Data.Array)
fixed (byte* pOutput = &block.Data.Array[block.End])
{
var output = pOutput + block.End;
//this line is needed to allow output be an register var
var output = pOutput;
var copied = 0;
for (; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan; copied += 4)

View File

@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
var bytes = Encoding.ASCII.GetBytes(str);
fixed (byte* ptr = bytes)
fixed (byte* ptr = &bytes[0])
{
return *(long*)ptr;
}

View File

@ -256,7 +256,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}
protected override StringValues GetValueFast(string key)
{{
switch(key.Length)
switch (key.Length)
{{{Each(loop.HeadersByLength, byLength => $@"
case {byLength.Key}:
{{{Each(byLength, header => $@"
@ -282,7 +282,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}
protected override bool TryGetValueFast(string key, out StringValues value)
{{
switch(key.Length)
switch (key.Length)
{{{Each(loop.HeadersByLength, byLength => $@"
case {byLength.Key}:
{{{Each(byLength, header => $@"
@ -307,7 +307,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}
protected override void SetValueFast(string key, StringValues value)
{{
switch(key.Length)
switch (key.Length)
{{{Each(loop.HeadersByLength, byLength => $@"
case {byLength.Key}:
{{{Each(byLength, header => $@"
@ -325,7 +325,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}
protected override void AddValueFast(string key, StringValues value)
{{
switch(key.Length)
switch (key.Length)
{{{Each(loop.HeadersByLength, byLength => $@"
case {byLength.Key}:
{{{Each(byLength, header => $@"
@ -347,7 +347,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}
protected override bool RemoveFast(string key)
{{
switch(key.Length)
switch (key.Length)
{{{Each(loop.HeadersByLength, byLength => $@"
case {byLength.Key}:
{{{Each(byLength, header => $@"
@ -405,8 +405,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_raw{header.Identifier} != null)
{{
output.CopyFrom(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length);
}} else ")}
foreach(var value in _{header.Identifier})
}}
else ")}
foreach (var value in _{header.Identifier})
{{
if (value != null)
{{
@ -419,8 +420,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}" : "")}
public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value)
{{
fixed(byte* ptr = keyBytes) {{ var pUB = ptr + keyOffset; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB;
switch(keyLength)
fixed (byte* ptr = &keyBytes[keyOffset])
{{
var pUB = ptr;
var pUL = (ulong*)pUB;
var pUI = (uint*)pUB;
var pUS = (ushort*)pUB;
switch (keyLength)
{{{Each(loop.HeadersByLength, byLength => $@"
case {byLength.Key}:
{{{Each(byLength, header => $@"
@ -440,7 +446,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}
")}}}
break;
")}}}}}
")}}}
}}
var key = System.Text.Encoding.ASCII.GetString(keyBytes, keyOffset, keyLength);
StringValues existing;
Unknown.TryGetValue(key, out existing);
@ -479,8 +486,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}
}}
}}
")}}}
";
")}}}";
}
public virtual void AfterCompile(AfterCompileContext context)
{