diff --git a/src/libraries/System.Memory/src/System/Buffers/Text/Base64Encoder.cs b/src/libraries/System.Memory/src/System/Buffers/Text/Base64Encoder.cs index 84748f9522b46426f20e7ad99a95a3a6fa180771..f55a4daa538bef64cb11982a17d04ff8e4d59c20 100644 --- a/src/libraries/System.Memory/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/libraries/System.Memory/src/System/Buffers/Text/Base64Encoder.cs @@ -577,16 +577,6 @@ private static unsafe uint EncodeAndPadTwo(byte* oneByte, ref byte encodingMap) private const int MaximumEncodeLength = (int.MaxValue / 4) * 3; // 1610612733 - // Pre-computing this table using a custom string(s_characters) and GenerateEncodingMapAndVerify (found in tests) - private static ReadOnlySpan EncodingMap => new byte[] { - 65, 66, 67, 68, 69, 70, 71, 72, //A..H - 73, 74, 75, 76, 77, 78, 79, 80, //I..P - 81, 82, 83, 84, 85, 86, 87, 88, //Q..X - 89, 90, 97, 98, 99, 100, 101, 102, //Y..Z, a..f - 103, 104, 105, 106, 107, 108, 109, 110, //g..n - 111, 112, 113, 114, 115, 116, 117, 118, //o..v - 119, 120, 121, 122, 48, 49, 50, 51, //w..z, 0..3 - 52, 53, 54, 55, 56, 57, 43, 47 //4..9, +, / - }; + private static ReadOnlySpan EncodingMap => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"u8; } } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ChunkedEncodingWriteStream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ChunkedEncodingWriteStream.cs index 9daea15fcae6e73adad112bb2673c0f794bba4e3..7a612f64c3854629deae6ad582e0eedae884bf14 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ChunkedEncodingWriteStream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ChunkedEncodingWriteStream.cs @@ -11,7 +11,7 @@ internal sealed partial class HttpConnection : IDisposable { private sealed class ChunkedEncodingWriteStream : HttpContentWriteStream { - private static readonly byte[] s_finalChunkBytes = { (byte)'0', (byte)'\r', (byte)'\n', (byte)'\r', (byte)'\n' }; + private static readonly byte[] s_finalChunkBytes = "0\r\n\r\n"u8.ToArray(); public ChunkedEncodingWriteStream(HttpConnection connection) : base(connection) { diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs index c8e813205f38edea7881292f12830df008305765..5f3626012a299eb3428f5afef594316009a24f1f 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs @@ -35,11 +35,7 @@ public sealed unsafe partial class HttpListener // 0.5 seconds per request. Respond with a 400 Bad Request. private const int UnknownHeaderLimit = 1000; - private static readonly byte[] s_wwwAuthenticateBytes = new byte[] - { - (byte) 'W', (byte) 'W', (byte) 'W', (byte) '-', (byte) 'A', (byte) 'u', (byte) 't', (byte) 'h', - (byte) 'e', (byte) 'n', (byte) 't', (byte) 'i', (byte) 'c', (byte) 'a', (byte) 't', (byte) 'e' - }; + private static readonly byte[] s_wwwAuthenticateBytes = "WWW-Authenticate"u8.ToArray(); private HttpListenerSession? _currentSession; diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mime/Base64Encoder.cs b/src/libraries/System.Net.Mail/src/System/Net/Mime/Base64Encoder.cs index 1c08b36f0536ac580e0651369bb2b6473abd0fa1..65dacb82da5e8a7f04fdaa7439f3083359181abc 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mime/Base64Encoder.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mime/Base64Encoder.cs @@ -7,14 +7,7 @@ namespace System.Net.Mime { internal sealed class Base64Encoder : ByteEncoder { - private static ReadOnlySpan Base64EncodeMap => new byte[] - { - 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, - 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, - 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, - 61 - }; + private static ReadOnlySpan Base64EncodeMap => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="u8; //the number of bytes needed to encode three bytes private const int SizeOfBase64EncodedBlock = 4; diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs index 3c83d86213bc14ee9701944ceac33c6a1df2dd09..a43c462ee72d9a8c6dc204d5634c0d54b8e05990 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs @@ -24,11 +24,11 @@ public class IPAddress internal const uint LoopbackMaskHostOrder = 0xFF000000; - public static readonly IPAddress IPv6Any = new IPAddress((ReadOnlySpan) new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0); - public static readonly IPAddress IPv6Loopback = new IPAddress((ReadOnlySpan) new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 0); + public static readonly IPAddress IPv6Any = new IPAddress((ReadOnlySpan)new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0); + public static readonly IPAddress IPv6Loopback = new IPAddress((ReadOnlySpan)new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 0); public static readonly IPAddress IPv6None = IPv6Any; - private static readonly IPAddress s_loopbackMappedToIPv6 = new IPAddress((ReadOnlySpan) new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1 }, 0); + private static readonly IPAddress s_loopbackMappedToIPv6 = new IPAddress((ReadOnlySpan)new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1 }, 0); /// /// For IPv4 addresses, this field stores the Address. diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/TlsFrameHelper.cs b/src/libraries/System.Net.Security/src/System/Net/Security/TlsFrameHelper.cs index 4a45573637967713c529dfdda6dd51100780b9f5..9fccacf845f8b53c64fc1380a20adbc033772221 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/TlsFrameHelper.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/TlsFrameHelper.cs @@ -149,11 +149,11 @@ public override string ToString() public delegate bool HelloExtensionCallback(ref TlsFrameInfo info, ExtensionType type, ReadOnlySpan extensionsData); - private static byte[] s_protocolMismatch13 = new byte[] { (byte)TlsContentType.Alert, 3, 4, 0, 2, 2, 70 }; - private static byte[] s_protocolMismatch12 = new byte[] { (byte)TlsContentType.Alert, 3, 3, 0, 2, 2, 70 }; - private static byte[] s_protocolMismatch11 = new byte[] { (byte)TlsContentType.Alert, 3, 2, 0, 2, 2, 70 }; - private static byte[] s_protocolMismatch10 = new byte[] { (byte)TlsContentType.Alert, 3, 1, 0, 2, 2, 70 }; - private static byte[] s_protocolMismatch30 = new byte[] { (byte)TlsContentType.Alert, 3, 0, 0, 2, 2, 40 }; + private static readonly byte[] s_protocolMismatch13 = new byte[] { (byte)TlsContentType.Alert, 3, 4, 0, 2, 2, 70 }; + private static readonly byte[] s_protocolMismatch12 = new byte[] { (byte)TlsContentType.Alert, 3, 3, 0, 2, 2, 70 }; + private static readonly byte[] s_protocolMismatch11 = new byte[] { (byte)TlsContentType.Alert, 3, 2, 0, 2, 2, 70 }; + private static readonly byte[] s_protocolMismatch10 = new byte[] { (byte)TlsContentType.Alert, 3, 1, 0, 2, 2, 70 }; + private static readonly byte[] s_protocolMismatch30 = new byte[] { (byte)TlsContentType.Alert, 3, 0, 0, 2, 2, 40 }; private const int UInt24Size = 3; private const int RandomSize = 32; diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Text/Base64Encoding.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Text/Base64Encoding.cs index 7799953ac71b515b69c1d1b0b1aa9696ca393757..06f13ac58ac0b135ecb5d13e1ea526ad760ed683 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Text/Base64Encoding.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Text/Base64Encoding.cs @@ -23,14 +23,7 @@ internal sealed class Base64Encoding : Encoding }; private const string Val2Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - private static ReadOnlySpan Val2byte => new byte[] - { - (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', (byte)'O', (byte)'P', - (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', - (byte)'g', (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', (byte)'v', - (byte)'w', (byte)'x', (byte)'y', (byte)'z', (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/' - }; + private static ReadOnlySpan Val2byte => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"u8; public override int GetMaxByteCount(int charCount) { diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs index af24916d0dc0c061a485d4270b52bcdd5be7c9ac..b15f29beb5237993694ae7314545be300a990665 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs @@ -23,7 +23,7 @@ internal sealed class PrefixHandle : IEquatable private int _offset; private int _length; private static readonly string[] s_prefixStrings = { "", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; - private static readonly byte[] s_prefixBuffer = { (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z' }; + private static readonly byte[] s_prefixBuffer = "abcdefghijklmnopqrstuvwxyz"u8.ToArray(); public PrefixHandle(XmlBufferReader bufferReader) { diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlUTF8TextWriter.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlUTF8TextWriter.cs index 936a4b4803c7bf613227ed80873994db0275d8f9..57285031c53daba96707bbdae97faa3296d18688 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlUTF8TextWriter.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlUTF8TextWriter.cs @@ -51,28 +51,12 @@ internal class XmlUTF8NodeWriter : XmlStreamNodeWriter private Encoding? _encoding; private char[]? _chars; - private static readonly byte[] s_startDecl = - { - (byte)'<', (byte)'?', (byte)'x', (byte)'m', (byte)'l', (byte)' ', - (byte)'v', (byte)'e', (byte)'r', (byte)'s', (byte)'i', (byte)'o', (byte)'n', (byte)'=', (byte)'"', (byte)'1', (byte)'.', (byte)'0', (byte)'"', (byte)' ', - (byte)'e', (byte)'n', (byte)'c', (byte)'o', (byte)'d', (byte)'i', (byte)'n', (byte)'g', (byte)'=', (byte)'"', - }; - private static readonly byte[] s_endDecl = - { - (byte)'"', (byte)'?', (byte)'>' - }; - private static readonly byte[] s_utf8Decl = - { - (byte)'<', (byte)'?', (byte)'x', (byte)'m', (byte)'l', (byte)' ', - (byte)'v', (byte)'e', (byte)'r', (byte)'s', (byte)'i', (byte)'o', (byte)'n', (byte)'=', (byte)'"', (byte)'1', (byte)'.', (byte)'0', (byte)'"', (byte)' ', - (byte)'e', (byte)'n', (byte)'c', (byte)'o', (byte)'d', (byte)'i', (byte)'n', (byte)'g', (byte)'=', (byte)'"', (byte)'u', (byte)'t', (byte)'f', (byte)'-', (byte)'8', (byte)'"', - (byte)'?', (byte)'>' - }; - private static ReadOnlySpan Digits => new byte[] - { - (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', - (byte) '8', (byte) '9', (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F' - }; + private static readonly byte[] s_startDecl = ""u8.ToArray(); + private static readonly byte[] s_utf8Decl = ""u8.ToArray(); + + private static ReadOnlySpan Digits => "0123456789ABCDEF"u8; + private static readonly bool[] s_defaultIsEscapedAttributeChar = new bool[] { true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,