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.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -145,23 +146,44 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
return string.Empty;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
if (value == "HTTP/1.1")
// 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 (value == "HTTP/1.0")
else if (ReferenceEquals(value, "HTTP/1.0"))
{
_httpVersion = Http.HttpVersion.Http10;
}
else
{
_httpVersion = Http.HttpVersion.Unset;
HttpVersionSetSlow(value);
}
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private void HttpVersionSetSlow(string value)
{
if (value == "HTTP/1.1")
{
_httpVersion = Http.HttpVersion.Http11;
}
else if (value == "HTTP/1.0")
{
_httpVersion = Http.HttpVersion.Http10;
}
else
{
_httpVersion = Http.HttpVersion.Unset;
}
}
public IHeaderDictionary RequestHeaders { get; set; }
public Stream RequestBody { get; set; }