From 2bf5a966cdf214a365b5c97f8d844924074097a8 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 15 Nov 2016 20:15:02 +0000 Subject: [PATCH] Fast path and inline HttpVersion.set --- .../Internal/Http/Frame.cs | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 2b7f56e882..5f336b71f6 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -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; }