React to corefxlab changes (#1539)

- Removed use of TryRead and follow the pin and use pattern in the other APIs

https://github.com/dotnet/corefxlab/pull/1348
This commit is contained in:
David Fowler 2017-03-23 06:52:24 -07:00 committed by Stephen Halter
parent ff99c4c865
commit f090b7a9c6
2 changed files with 16 additions and 7 deletions

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
// Prepare the first span
var span = buffer.First.Span;
var lineIndex = span.SequentialIndexOf(ByteLF);
var lineIndex = span.IndexOf(ByteLF);
if (lineIndex >= 0)
{
consumed = buffer.Move(consumed, lineIndex + 1);
@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
index = reader.Index;
}
var endIndex = new Span<byte>(pBuffer + index, remaining).SequentialIndexOf(ByteLF);
var endIndex = new Span<byte>(pBuffer + index, remaining).IndexOf(ByteLF);
var length = 0;
if (endIndex != -1)

View File

@ -270,23 +270,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
/// <param name="knownScheme">A reference to the known scheme, if the input matches any</param>
/// <returns>True when memory starts with known http or https schema</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool GetKnownHttpScheme(this Span<byte> span, out HttpScheme knownScheme)
public static unsafe bool GetKnownHttpScheme(this Span<byte> span, out HttpScheme knownScheme)
{
if (span.TryRead<ulong>(out var value))
fixed (byte* data = &span.DangerousGetPinnableReference())
{
if ((value & _mask7Chars) == _httpSchemeLong)
return GetKnownHttpScheme(data, span.Length, out knownScheme);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe bool GetKnownHttpScheme(byte* location, int length, out HttpScheme knownScheme)
{
if (length >= sizeof(ulong))
{
var scheme = *(ulong*)location;
if ((scheme & _mask7Chars) == _httpSchemeLong)
{
knownScheme = HttpScheme.Http;
return true;
}
if (value == _httpsSchemeLong)
if (scheme == _httpsSchemeLong)
{
knownScheme = HttpScheme.Https;
return true;
}
}
knownScheme = HttpScheme.Unknown;
return false;
}