Repository: dotnet/runtime
File: src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/DecompressionHandler.cs (C#)

Code before:
    internal sealed class DecompressionHandler : HttpMessageHandlerStage
    {
        private readonly HttpMessageHandlerStage _innerHandler;
        private readonly DecompressionMethods _decompressionMethods;

        private const string Gzip = "gzip";
        private const string Deflate = "deflate";
        private const string Brotli = "br";
        private const string Zstd = "zstd";
        private static readonly StringWithQualityHeaderValue s_gzipHeaderValue = new(Gzip);
        private static readonly StringWithQualityHeaderValue s_deflateHeaderValue = new(Deflate);
        private static readonly StringWithQualityHeaderValue s_brotliHeaderValue = new(Brotli);
        private static readonly StringWithQualityHeaderValue s_zstdHeaderValue = new(Zstd);

        /// <summary>Header value for all enabled decompression methods, e.g. "gzip, deflate".</summary>
        private readonly string _acceptEncodingHeaderValue;

        public DecompressionHandler(DecompressionMethods decompressionMethods, HttpMessageHandlerStage innerHandler)
        {
            Debug.Assert(decompressionMethods != DecompressionMethods.None);
            Debug.Assert(innerHandler != null);

            _decompressionMethods = decompressionMethods;
            _innerHandler = innerHandler;

            Span<string?> methods = ["", "", "", ""];
            int count = 0;
            if (GZipEnabled) methods[count++] = Gzip;
            if (DeflateEnabled) methods[count++] = Deflate;
            if (BrotliEnabled) methods[count++] = Brotli;
            if (ZstandardEnabled) methods[count++] = Zstd;
            _acceptEncodingHeaderValue = string.Join(", ", methods.Slice(0, count));
        }

        internal bool GZipEnabled => (_decompressionMethods & DecompressionMethods.GZip) != 0;
        internal bool DeflateEnabled => (_decompressionMethods & DecompressionMethods.Deflate) != 0;
        internal bool BrotliEnabled => (_decompressionMethods & DecompressionMethods.Brotli) != 0;
        internal bool ZstandardEnabled => (_decompressionMethods & DecompressionMethods.Zstandard) != 0;

        private static bool EncodingExists(HttpHeaderValueCollection<StringWithQualityHeaderValue> acceptEncodingHeader, string encoding)
        {
            foreach (StringWithQualityHeaderValue existingEncoding in acceptEncodingHeader)
            {
                if (string.Equals(existingEncoding.Value, encoding, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }

            return false;
        }

Review comment (performance):
```suggestion
            Span<string?> methods = [null, null, null, null];
```
A bit more efficient

Code after:
    internal sealed class DecompressionHandler : HttpMessageHandlerStage
    {
        private readonly HttpMessageHandlerStage _innerHandler;
        private readonly DecompressionMethods _decompressionMethods;

        private const string Gzip = "gzip";
        private const string Deflate = "deflate";
        private const string Brotli = "br";
        private const string Zstd = "zstd";
        private static readonly StringWithQualityHeaderValue s_gzipHeaderValue = new(Gzip);
        private static readonly StringWithQualityHeaderValue s_deflateHeaderValue = new(Deflate);
        private static readonly StringWithQualityHeaderValue s_brotliHeaderValue = new(Brotli);
        private static readonly StringWithQualityHeaderValue s_zstdHeaderValue = new(Zstd);

        /// <summary>Header value for all enabled decompression methods, e.g. "gzip, deflate".</summary>
        private readonly string _acceptEncodingHeaderValue;

        public DecompressionHandler(DecompressionMethods decompressionMethods, HttpMessageHandlerStage innerHandler)
        {
            Debug.Assert(decompressionMethods != DecompressionMethods.None);
            Debug.Assert(innerHandler != null);

            _decompressionMethods = decompressionMethods;
            _innerHandler = innerHandler;

            Span<string?> methods = [null, null, null, null];
            int count = 0;
            if (GZipEnabled) methods[count++] = Gzip;
            if (DeflateEnabled) methods[count++] = Deflate;
            if (BrotliEnabled) methods[count++] = Brotli;
            if (ZstandardEnabled) methods[count++] = Zstd;
            _acceptEncodingHeaderValue = string.Join(", ", methods.Slice(0, count));
        }

        internal bool GZipEnabled => (_decompressionMethods & DecompressionMethods.GZip) != 0;
        internal bool DeflateEnabled => (_decompressionMethods & DecompressionMethods.Deflate) != 0;
        internal bool BrotliEnabled => (_decompressionMethods & DecompressionMethods.Brotli) != 0;
        internal bool ZstandardEnabled => (_decompressionMethods & DecompressionMethods.Zstandard) != 0;

        private static bool EncodingExists(HttpHeaderValueCollection<StringWithQualityHeaderValue> acceptEncodingHeader, string encoding)
        {
            foreach (StringWithQualityHeaderValue existingEncoding in acceptEncodingHeader)
            {
                if (string.Equals(existingEncoding.Value, encoding, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }

            return false;
        }