From: Miha Zupan Date: Fri, 27 Jan 2023 18:43:06 +0000 (-0800) Subject: Avoid allocations in 'Transfer-Encoding: Chunked' check (#81253) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~4384 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d2eed6c852af334b20c451abf7fc68ec13fbb112;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Avoid allocations in 'Transfer-Encoding: Chunked' check (#81253) --- diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpGeneralHeaders.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpGeneralHeaders.cs index 0368349..b1b7176 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpGeneralHeaders.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpGeneralHeaders.cs @@ -81,14 +81,25 @@ namespace System.Net.Http.Headers internal static bool? GetTransferEncodingChunked(HttpHeaders parent, HttpGeneralHeaders? headers) { - if (parent.ContainsParsedValue(KnownHeaders.TransferEncoding.Descriptor, HeaderUtilities.TransferEncodingChunked)) + if (parent.TryGetHeaderValue(KnownHeaders.TransferEncoding.Descriptor, out object? value)) { - return true; + // Fast-path for the very common case where "chunked" is the only value. + if (value is string stringValue && stringValue.Equals("chunked", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + if (parent.ContainsParsedValue(KnownHeaders.TransferEncoding.Descriptor, HeaderUtilities.TransferEncodingChunked)) + { + return true; + } } + if (headers != null && headers._transferEncodingChunkedSet) { return false; } + return null; }