Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit f090b7a

Browse files
davidfowlhalter73
authored andcommitted
React to corefxlab changes (#1539)
- Removed use of TryRead and follow the pin and use pattern in the other APIs dotnet/corefxlab#1348
1 parent ff99c4c commit f090b7a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/KestrelHttpParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public unsafe bool ParseRequestLine<T>(T handler, ReadableBuffer buffer, out Rea
3636

3737
// Prepare the first span
3838
var span = buffer.First.Span;
39-
var lineIndex = span.SequentialIndexOf(ByteLF);
39+
var lineIndex = span.IndexOf(ByteLF);
4040
if (lineIndex >= 0)
4141
{
4242
consumed = buffer.Move(consumed, lineIndex + 1);
@@ -255,7 +255,7 @@ public unsafe bool ParseHeaders<T>(T handler, ReadableBuffer buffer, out ReadCur
255255
index = reader.Index;
256256
}
257257

258-
var endIndex = new Span<byte>(pBuffer + index, remaining).SequentialIndexOf(ByteLF);
258+
var endIndex = new Span<byte>(pBuffer + index, remaining).IndexOf(ByteLF);
259259
var length = 0;
260260

261261
if (endIndex != -1)

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,32 @@ internal unsafe static HttpVersion GetKnownVersion(byte* location, int length)
270270
/// <param name="knownScheme">A reference to the known scheme, if the input matches any</param>
271271
/// <returns>True when memory starts with known http or https schema</returns>
272272
[MethodImpl(MethodImplOptions.AggressiveInlining)]
273-
public static bool GetKnownHttpScheme(this Span<byte> span, out HttpScheme knownScheme)
273+
public static unsafe bool GetKnownHttpScheme(this Span<byte> span, out HttpScheme knownScheme)
274274
{
275-
if (span.TryRead<ulong>(out var value))
275+
fixed (byte* data = &span.DangerousGetPinnableReference())
276+
{
277+
return GetKnownHttpScheme(data, span.Length, out knownScheme);
278+
}
279+
}
280+
281+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
282+
private static unsafe bool GetKnownHttpScheme(byte* location, int length, out HttpScheme knownScheme)
283+
{
284+
if (length >= sizeof(ulong))
276285
{
277-
if ((value & _mask7Chars) == _httpSchemeLong)
286+
var scheme = *(ulong*)location;
287+
if ((scheme & _mask7Chars) == _httpSchemeLong)
278288
{
279289
knownScheme = HttpScheme.Http;
280290
return true;
281291
}
282292

283-
if (value == _httpsSchemeLong)
293+
if (scheme == _httpsSchemeLong)
284294
{
285295
knownScheme = HttpScheme.Https;
286296
return true;
287297
}
288298
}
289-
290299
knownScheme = HttpScheme.Unknown;
291300
return false;
292301
}

0 commit comments

Comments
 (0)