Skip to content

Commit

Permalink
Remove some char[] allocations from Split usage (dotnet#32301)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Feb 14, 2020
1 parent 7edf03d commit 1456b7f
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private AggregateCatalog InnerCatalog
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
}

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++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3690,7 +3690,7 @@ internal IndexField[] ParseSortString(string sortString)
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++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
// 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]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ internal static bool ProcessWebSocketProtocolHeader(string clientSecWebSocketPro
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ internal string ExitMessage
/// </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);
Expand Down Expand Up @@ -1064,7 +1064,7 @@ private int GetPortV6(string responseString)
// 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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ internal static string GetCSharpName(Type t)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal static string FromXmlNmTokens(string nmTokens)
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++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
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++)
Expand Down

0 comments on commit 1456b7f

Please sign in to comment.