diff options
author | Geoff Kizer <geoffrek> | 2017-08-15 01:26:08 +0300 |
---|---|---|
committer | Geoff Kizer <geoffrek> | 2017-08-15 01:26:08 +0300 |
commit | b29703658f43e9b01638aa4cdf0176f48c5c0fc3 (patch) | |
tree | 19a28194dce759048c45a7ac82a6b82b2d46605f /src/System.Net.Http | |
parent | 0589dfd640c1c2e40ea878efae44a74494222522 (diff) |
address PR feedback
Diffstat (limited to 'src/System.Net.Http')
3 files changed, 30 insertions, 35 deletions
diff --git a/src/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs b/src/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs index 23f133eaaa..cd28c40b9a 100644 --- a/src/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs +++ b/src/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs @@ -41,18 +41,13 @@ namespace System return true; } - internal static string GetStringFromByteSpan(ReadOnlySpan<byte> bytes) + internal static unsafe string GetStringFromByteSpan(ReadOnlySpan<byte> bytes) { - string s; - unsafe + // TODO: Use new Span-based Encoding overload when available + fixed (byte* p = &bytes.DangerousGetPinnableReference()) { - fixed (byte* p = &bytes.DangerousGetPinnableReference()) - { - s = Encoding.ASCII.GetString(p, bytes.Length); - } + return Encoding.ASCII.GetString(p, bytes.Length); } - - return s; } } } diff --git a/src/System.Net.Http/src/System/Net/Http/Headers/HeaderDescriptor.cs b/src/System.Net.Http/src/System/Net/Http/Headers/HeaderDescriptor.cs index 4b4ca304ab..3737e44709 100644 --- a/src/System.Net.Http/src/System/Net/Http/Headers/HeaderDescriptor.cs +++ b/src/System.Net.Http/src/System/Net/Http/Headers/HeaderDescriptor.cs @@ -100,9 +100,9 @@ namespace System.Net.Http.Headers } // If it's a known header value, use the known value instead of allocating a new string. - string[] knownValues = _knownHeader?.KnownValues; - if (knownValues != null) + if (_knownHeader != null && _knownHeader.KnownValues != null) { + string[] knownValues = _knownHeader.KnownValues; for (int i = 0; i < knownValues.Length; i++) { if (ByteArrayHelpers.EqualsOrdinalAsciiIgnoreCase(knownValues[i], headerValue)) diff --git a/src/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs b/src/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs index bdad477aec..ac209a1fba 100644 --- a/src/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs +++ b/src/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs @@ -98,7 +98,7 @@ namespace System.Net.Http.Headers private interface IHeaderNameAccessor { int Length { get; } - char CharAt(int index); + char this[int index] { get; } } private struct StringAccessor : IHeaderNameAccessor @@ -111,14 +111,14 @@ namespace System.Net.Http.Headers } public int Length => _string.Length; - public char CharAt(int index) => _string[index]; + public char this[int index] => _string[index]; } // Can't use Span here as it's unsupported. private unsafe struct BytePtrAccessor : IHeaderNameAccessor { - private byte* _p; - private int _length; + private readonly byte* _p; + private readonly int _length; public BytePtrAccessor(byte* p, int length) { @@ -127,7 +127,7 @@ namespace System.Net.Http.Headers } public int Length => _length; - public char CharAt(int index) => (char)_p[index]; + public char this[int index] => (char)_p[index]; } // Find possible known header match via lookup on length and a distinguishing char for that length. @@ -144,7 +144,7 @@ namespace System.Net.Http.Headers return TE; // TE case 3: - switch (key.CharAt(0)) + switch (key[0]) { case 'A': case 'a': return Age; // [A]ge case 'P': case 'p': return P3P; // [P]3P @@ -154,7 +154,7 @@ namespace System.Net.Http.Headers break; case 4: - switch (key.CharAt(0)) + switch (key[0]) { case 'D': case 'd': return Date; // [D]ate case 'E': case 'e': return ETag; // [E]Tag @@ -166,7 +166,7 @@ namespace System.Net.Http.Headers break; case 5: - switch (key.CharAt(0)) + switch (key[0]) { case 'A': case 'a': return Allow; // [A]llow case 'R': case 'r': return Range; // [R]ange @@ -174,7 +174,7 @@ namespace System.Net.Http.Headers break; case 6: - switch (key.CharAt(0)) + switch (key[0]) { case 'A': case 'a': return Accept; // [A]ccept case 'C': case 'c': return Cookie; // [C]ookie @@ -186,7 +186,7 @@ namespace System.Net.Http.Headers break; case 7: - switch (key.CharAt(0)) + switch (key[0]) { case 'A': case 'a': return AltSvc; // [A]lt-Svc case 'C': case 'c': return Cookie2; // [C]ookie2 @@ -199,7 +199,7 @@ namespace System.Net.Http.Headers break; case 8: - switch (key.CharAt(3)) + switch (key[3]) { case 'M': case 'm': return IfMatch; // If-[M]atch case 'R': case 'r': return IfRange; // If-[R]ange @@ -208,7 +208,7 @@ namespace System.Net.Http.Headers break; case 10: - switch (key.CharAt(0)) + switch (key[0]) { case 'C': case 'c': return Connection; // [C]onnection case 'K': case 'k': return KeepAlive; // [K]eep-Alive @@ -218,7 +218,7 @@ namespace System.Net.Http.Headers break; case 11: - switch (key.CharAt(0)) + switch (key[0]) { case 'C': case 'c': return ContentMD5; // [C]ontent-MD5 case 'R': case 'r': return RetryAfter; // [R]etry-After @@ -227,7 +227,7 @@ namespace System.Net.Http.Headers break; case 12: - switch (key.CharAt(2)) + switch (key[2]) { case 'C': case 'c': return AcceptPatch; // Ac[c]ept-Patch case 'N': case 'n': return ContentType; // Co[n]tent-Type @@ -239,7 +239,7 @@ namespace System.Net.Http.Headers break; case 13: - switch (key.CharAt(6)) + switch (key[6]) { case '-': return AcceptRanges; // Accept[-]Ranges case 'I': case 'i': return Authorization; // Author[i]zation @@ -251,7 +251,7 @@ namespace System.Net.Http.Headers break; case 14: - switch (key.CharAt(0)) + switch (key[0]) { case 'A': case 'a': return AcceptCharset; // [A]ccept-Charset case 'C': case 'c': return ContentLength; // [C]ontent-Length @@ -259,7 +259,7 @@ namespace System.Net.Http.Headers break; case 15: - switch (key.CharAt(7)) + switch (key[7]) { case '-': return XFrameOptions; // X-Frame[-]Options case 'M': case 'm': return XUACompatible; // X-UA-Co[m]patible @@ -270,7 +270,7 @@ namespace System.Net.Http.Headers break; case 16: - switch (key.CharAt(11)) + switch (key[11]) { case 'O': case 'o': return ContentEncoding; // Content-Enc[o]ding case 'G': case 'g': return ContentLanguage; // Content-Lan[g]uage @@ -282,7 +282,7 @@ namespace System.Net.Http.Headers break; case 17: - switch (key.CharAt(0)) + switch (key[0]) { case 'I': case 'i': return IfModifiedSince; // [I]f-Modified-Since case 'S': case 's': return SecWebSocketKey; // [S]ec-WebSocket-Key @@ -291,7 +291,7 @@ namespace System.Net.Http.Headers break; case 18: - switch (key.CharAt(0)) + switch (key[0]) { case 'P': case 'p': return ProxyAuthenticate; // [P]roxy-Authenticate case 'X': case 'x': return XContentDuration; // [X]-Content-Duration @@ -299,7 +299,7 @@ namespace System.Net.Http.Headers break; case 19: - switch (key.CharAt(0)) + switch (key[0]) { case 'C': case 'c': return ContentDisposition; // [C]ontent-Disposition case 'I': case 'i': return IfUnmodifiedSince; // [I]f-Unmodified-Since @@ -314,7 +314,7 @@ namespace System.Net.Http.Headers return SecWebSocketVersion; // Sec-WebSocket-Version case 22: - switch (key.CharAt(0)) + switch (key[0]) { case 'A': case 'a': return AccessControlMaxAge; // [A]ccess-Control-Max-Age case 'S': case 's': return SecWebSocketProtocol; // [S]ec-WebSocket-Protocol @@ -329,7 +329,7 @@ namespace System.Net.Http.Headers return SecWebSocketExtensions; // Sec-WebSocket-Extensions case 25: - switch (key.CharAt(0)) + switch (key[0]) { case 'S': case 's': return StrictTransportSecurity; // [S]trict-Transport-Security case 'U': case 'u': return UpgradeInsecureRequests; // [U]pgrade-Insecure-Requests @@ -340,7 +340,7 @@ namespace System.Net.Http.Headers return AccessControlAllowOrigin; // Access-Control-Allow-Origin case 28: - switch (key.CharAt(21)) + switch (key[21]) { case 'H': case 'h': return AccessControlAllowHeaders; // Access-Control-Allow-[H]eaders case 'M': case 'm': return AccessControlAllowMethods; // Access-Control-Allow-[M]ethods |