Remove some char[] allocations from Split usage (#32301)
authorStephen Toub <stoub@microsoft.com>
Fri, 14 Feb 2020 18:21:50 +0000 (10:21 -0800)
committerGitHub <noreply@github.com>
Fri, 14 Feb 2020 18:21:50 +0000 (10:21 -0800)
12 files changed:
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ApplicationCatalog.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/Drawing/RectangleConverter.cs
src/libraries/System.Data.Common/src/System/Data/DataTable.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ColorConverter.cs
src/libraries/System.Drawing.Common/src/System/Drawing/PointConverter.cs
src/libraries/System.Drawing.Common/src/System/Drawing/RectangleConverter.cs
src/libraries/System.Drawing.Common/src/System/Drawing/SizeConverter.cs
src/libraries/System.Net.HttpListener/src/System/Net/WebSockets/HttpWebSocket.cs
src/libraries/System.Net.Requests/src/System/Net/FtpControlStream.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeIdentifier.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/Xmlcustomformatter.cs
src/libraries/System.Windows.Extensions/src/System/Drawing/Printing/MarginsConverter.cs

index 8a31d54..3fc5ad7 100644 (file)
@@ -85,7 +85,7 @@ namespace System.ComponentModel.Composition.Hosting
                             string? relativeSearchPath = AppDomain.CurrentDomain.RelativeSearchPath;
                             if (!string.IsNullOrEmpty(relativeSearchPath))
                             {
-                                string[] probingPaths = relativeSearchPath.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
+                                string[] probingPaths = relativeSearchPath.Split(';', StringSplitOptions.RemoveEmptyEntries);
                                 foreach (var probingPath in probingPaths)
                                 {
                                     var path = Path.Combine(location, probingPath);
index 1c4cf21..54c099e 100644 (file)
@@ -40,7 +40,7 @@ namespace System.Drawing
                 }
 
                 char sep = culture.TextInfo.ListSeparator[0];
-                string[] tokens = text.Split(new char[] { sep });
+                string[] tokens = text.Split(sep);
                 int[] values = new int[tokens.Length];
                 TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));
                 for (int i = 0; i < values.Length; i++)
index 7f7e45b..181ec8b 100644 (file)
@@ -3690,7 +3690,7 @@ namespace System.Data
             IndexField[] indexDesc = Array.Empty<IndexField>();
             if ((null != sortString) && (0 < sortString.Length))
             {
-                string[] split = sortString.Split(new char[] { ',' });
+                string[] split = sortString.Split(',');
                 indexDesc = new IndexField[split.Length];
 
                 for (int i = 0; i < split.Length; i++)
index feda73c..b6b654e 100644 (file)
@@ -167,7 +167,7 @@ namespace System.Drawing {
                         // Nope.  Parse the RGBA from the text.
                         //
                         if (obj == null) {
-                            string[] tokens = text.Split(new char[] {sep});
+                            string[] tokens = text.Split(sep);
                             int[] values = new int[tokens.Length];
                             for (int i = 0; i < values.Length; i++) {
                                 values[i] = unchecked((int)intConverter.ConvertFromString(context, culture, tokens[i]));
index 0c84114..cbe20d1 100644 (file)
@@ -71,7 +71,7 @@ namespace System.Drawing {
                         culture = CultureInfo.CurrentCulture;
                     }
                     char sep = culture.TextInfo.ListSeparator[0];
-                    string[] tokens = text.Split(new char[] {sep});
+                    string[] tokens = text.Split(sep);
                     int[] values = new int[tokens.Length];
                     TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));
                     for (int i = 0; i < values.Length; i++) {
index f161d0a..8a92db4 100644 (file)
@@ -71,7 +71,7 @@ namespace System.Drawing {
                         culture = CultureInfo.CurrentCulture;
                     }
                     char sep = culture.TextInfo.ListSeparator[0];
-                    string[] tokens = text.Split(new char[] {sep});
+                    string[] tokens = text.Split(sep);
                     int[] values = new int[tokens.Length];
                     TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));
                     for (int i = 0; i < values.Length; i++) {
index 41c1045..9404d91 100644 (file)
@@ -71,7 +71,7 @@ namespace System.Drawing {
                         culture = CultureInfo.CurrentCulture;
                     }
                     char sep = culture.TextInfo.ListSeparator[0];
-                    string[] tokens = text.Split(new char[] {sep});
+                    string[] tokens = text.Split(sep);
                     int[] values = new int[tokens.Length];
                     TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));
                     for (int i = 0; i < values.Length; i++) {
index d194f4a..c538186 100644 (file)
@@ -62,8 +62,7 @@ namespace System.Net.WebSockets
             // here, we know that the client has specified something, it's not empty
             // and the server has specified exactly one protocol
 
-            string[] requestProtocols = clientSecWebSocketProtocol.Split(new char[] { ',' },
-                StringSplitOptions.RemoveEmptyEntries);
+            string[] requestProtocols = clientSecWebSocketProtocol.Split(',', StringSplitOptions.RemoveEmptyEntries);
             acceptProtocol = subProtocol;
 
             // client specified protocols, serverOptions has exactly 1 non-empty entry. Check that
index f083e9a..c5ac697 100644 (file)
@@ -882,7 +882,7 @@ namespace System.Net
         /// </summary>
         private long GetContentLengthFrom213Response(string responseString)
         {
-            string[] parsedList = responseString.Split(new char[] { ' ' });
+            string[] parsedList = responseString.Split(' ');
             if (parsedList.Length < 2)
                 throw new FormatException(SR.Format(SR.net_ftp_response_invalid_format, responseString));
             return Convert.ToInt64(parsedList[1], NumberFormatInfo.InvariantInfo);
@@ -1064,7 +1064,7 @@ namespace System.Net
             // addressInfo will contain a string of format "|||<tcp-port>|"
             string addressInfo = responseString.Substring(pos1 + 1, pos2 - pos1 - 1);
 
-            string[] parsedList = addressInfo.Split(new char[] { '|' });
+            string[] parsedList = addressInfo.Split('|');
             if (parsedList.Length < 4)
                 throw new FormatException(SR.Format(SR.net_ftp_response_invalid_format, responseString));
 
index cdbbf07..5dcac01 100644 (file)
@@ -222,7 +222,7 @@ namespace System.Xml.Serialization
             string ns = t.Namespace;
             if (ns != null && ns.Length > 0)
             {
-                string[] parts = ns.Split(new char[] { '.' });
+                string[] parts = ns.Split('.');
                 for (int i = 0; i < parts.Length; i++)
                 {
                     EscapeKeywords(parts[i], sb);
index f9d6bdd..026e357 100644 (file)
@@ -133,7 +133,7 @@ namespace System.Xml.Serialization
                 return FromXmlNmToken(nmTokens);
             else
             {
-                string[] toks = nmTokens.Split(new char[] { ' ' });
+                string[] toks = nmTokens.Split(' ');
                 StringBuilder sb = new StringBuilder();
                 for (int i = 0; i < toks.Length; i++)
                 {
index e98593a..fe7a45f 100644 (file)
@@ -63,7 +63,7 @@ namespace System.Drawing.Printing
                         culture = CultureInfo.CurrentCulture;
                     }
                     char sep = culture.TextInfo.ListSeparator[0];
-                    string[] tokens = text.Split(new char[] { sep });
+                    string[] tokens = text.Split(sep);
                     int[] values = new int[tokens.Length];
                     TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));
                     for (int i = 0; i < values.Length; i++)