Fast path and inline HttpVersion.set

This commit is contained in:
Ben Adams 2016-11-15 20:15:02 +00:00 committed by Stephen Halter
parent b2d45c3dd0
commit 2bf5a966cd
1 changed files with 25 additions and 3 deletions

View File

@ -7,6 +7,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -145,7 +146,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
return string.Empty; return string.Empty;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set set
{
// GetKnownVersion returns versions which ReferenceEquals interned string
// As most common path, check for this only in fast-path and inline
if (ReferenceEquals(value, "HTTP/1.1"))
{
_httpVersion = Http.HttpVersion.Http11;
}
else if (ReferenceEquals(value, "HTTP/1.0"))
{
_httpVersion = Http.HttpVersion.Http10;
}
else
{
HttpVersionSetSlow(value);
}
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private void HttpVersionSetSlow(string value)
{ {
if (value == "HTTP/1.1") if (value == "HTTP/1.1")
{ {
@ -160,7 +183,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
_httpVersion = Http.HttpVersion.Unset; _httpVersion = Http.HttpVersion.Unset;
} }
} }
}
public IHeaderDictionary RequestHeaders { get; set; } public IHeaderDictionary RequestHeaders { get; set; }
public Stream RequestBody { get; set; } public Stream RequestBody { get; set; }