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

@ -4237,7 +4237,12 @@ 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;
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);
@ -9042,7 +9048,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawConnection != null)
{
output.CopyFrom(_rawConnection, 0, _rawConnection.Length);
} else
}
else
foreach (var value in _Connection)
{
if (value != null)
@ -9058,7 +9065,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawDate != null)
{
output.CopyFrom(_rawDate, 0, _rawDate.Length);
} else
}
else
foreach (var value in _Date)
{
if (value != null)
@ -9110,7 +9118,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawTransferEncoding != null)
{
output.CopyFrom(_rawTransferEncoding, 0, _rawTransferEncoding.Length);
} else
}
else
foreach (var value in _TransferEncoding)
{
if (value != null)
@ -9174,7 +9183,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawContentLength != null)
{
output.CopyFrom(_rawContentLength, 0, _rawContentLength.Length);
} else
}
else
foreach (var value in _ContentLength)
{
if (value != null)
@ -9358,7 +9368,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_rawServer != null)
{
output.CopyFrom(_rawServer, 0, _rawServer.Length);
} else
}
else
foreach (var value in _Server)
{
if (value != null)
@ -9480,7 +9491,12 @@ 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;
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

@ -405,7 +405,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (_raw{header.Identifier} != null)
{{
output.CopyFrom(_raw{header.Identifier}, 0, _raw{header.Identifier}.Length);
}} else ")}
}}
else ")}
foreach (var value in _{header.Identifier})
{{
if (value != null)
@ -419,7 +420,12 @@ 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;
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}:
@ -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)
{