Remove some extra static arrays used in Split() (#76003)
authorIlya <darpa@yandex.ru>
Thu, 29 Sep 2022 15:23:24 +0000 (20:23 +0500)
committerGitHub <noreply@github.com>
Thu, 29 Sep 2022 15:23:24 +0000 (17:23 +0200)
* Remove some extra static arrays used in Split
* Remove const

src/libraries/System.Net.Mail/src/System/Net/Mime/MimeBasePart.cs
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Connections.cs

index 50f1d36..68c3cd2 100644 (file)
@@ -43,7 +43,6 @@ namespace System.Net.Mime
         }
 
         private static readonly char[] s_headerValueSplitChars = new char[] { '\r', '\n', ' ' };
-        private static readonly char[] s_questionMarkSplitChars = new char[] { '?' };
 
         internal static string DecodeHeaderValue(string? value)
         {
@@ -65,7 +64,7 @@ namespace System.Net.Mime
                 //the third is the unicode encoding type, and the fourth is encoded message itself.  '?' is not valid inside of
                 //an encoded string other than as a separator for these five parts.
                 //If this check fails, the string is either not encoded or cannot be decoded by this method
-                string[] subStrings = foldedSubString.Split(s_questionMarkSplitChars);
+                string[] subStrings = foldedSubString.Split('?');
                 if ((subStrings.Length != 5 || subStrings[0] != "=" || subStrings[4] != "="))
                 {
                     return value;
index 3d25db4..248ce38 100644 (file)
@@ -9,8 +9,6 @@ namespace System.Net.NetworkInformation
 {
     internal static partial class StringParsingHelpers
     {
-        private static readonly string[] s_newLineSeparator = new string[] { Environment.NewLine }; // Used for string splitting
-
         internal static int ParseNumSocketConnections(string filePath, string protocolName)
         {
             // Parse the number of active connections out of /proc/net/sockstat
@@ -32,7 +30,7 @@ namespace System.Net.NetworkInformation
             if (tcp4ConnectionsFile != null)
             {
                 string tcp4FileContents = ReadAllText(tcp4ConnectionsFile);
-                v4connections = tcp4FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries);
+                v4connections = tcp4FileContents.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
             }
             else
             {
@@ -42,7 +40,7 @@ namespace System.Net.NetworkInformation
             if (tcp6ConnectionsFile != null)
             {
                 string tcp6FileContents = ReadAllText(tcp6ConnectionsFile);
-                v6connections = tcp6FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries);
+                v6connections = tcp6FileContents.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
             }
             else
             {
@@ -112,7 +110,7 @@ namespace System.Net.NetworkInformation
             if (tcp4ConnectionsFile != null)
             {
                 string tcp4FileContents = ReadAllText(tcp4ConnectionsFile);
-                v4connections = tcp4FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries);
+                v4connections = tcp4FileContents.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
             }
             else
             {
@@ -122,7 +120,7 @@ namespace System.Net.NetworkInformation
             if (tcp6ConnectionsFile != null)
             {
                 string tcp6FileContents = ReadAllText(tcp6ConnectionsFile);
-                v6connections = tcp6FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries);
+                v6connections = tcp6FileContents.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
             }
             else
             {
@@ -192,7 +190,7 @@ namespace System.Net.NetworkInformation
             if (udp4File != null)
             {
                 string udp4FileContents = ReadAllText(udp4File);
-                v4connections = udp4FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries);
+                v4connections = udp4FileContents.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
             }
             else
             {
@@ -202,7 +200,7 @@ namespace System.Net.NetworkInformation
             if (udp6File != null)
             {
                 string udp6FileContents = ReadAllText(udp6File);
-                v6connections = udp6FileContents.Split(s_newLineSeparator, StringSplitOptions.RemoveEmptyEntries);
+                v6connections = udp6FileContents.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
             }
             else
             {