Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove several unnecessary arrays used with String.Split #36304

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/libraries/Common/src/System/Net/Mail/MailBnfHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ internal static class MailBnfHelper
internal const char Comma = ',';
internal const char Dot = '.';

private static readonly char[] s_colonSeparator = new char[] { ':' };

// NOTE: See RFC 2822 for more detail. By default, every value in the array is false and only
// those values which are allowed in that particular set are then set to true. The numbers
// annotating each definition below are the range of ASCII values which are allowed in that definition.
Expand Down Expand Up @@ -317,7 +315,7 @@ internal static string ReadToken(string data, ref int offset, StringBuilder? bui
localBuilder.Append(' ');
}

string[] offsetFields = offset.Split(s_colonSeparator);
string[] offsetFields = offset.Split(':');
localBuilder.Append(offsetFields[0]);
localBuilder.Append(offsetFields[1]);
return (builder != null ? null : localBuilder.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace System.ComponentModel.Design
public abstract class DesignerOptionService : IDesignerOptionService
{
private DesignerOptionCollection _options;
private static readonly char[] s_slash = { '\\' };

/// <summary>
/// Returns the options collection for this service. There is
Expand Down Expand Up @@ -70,7 +69,7 @@ private PropertyDescriptor GetOptionProperty(string pageName, string valueName)
throw new ArgumentNullException(nameof(valueName));
}

string[] optionNames = pageName.Split(s_slash);
string[] optionNames = pageName.Split('\\');

DesignerOptionCollection options = Options;
foreach (string optionName in optionNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace System.ComponentModel
/// </summary>
public class EnumConverter : TypeConverter
{
private static readonly char[] s_separators = { ',' };

/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.EnumConverter'/> class for the given
/// type.
Expand Down Expand Up @@ -83,7 +81,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
{
bool isUnderlyingTypeUInt64 = Enum.GetUnderlyingType(EnumType) == typeof(ulong);
long convertedValue = 0;
string[] values = strValue.Split(s_separators);
string[] values = strValue.Split(',');
foreach (string v in values)
{
convertedValue |= GetEnumValue(isUnderlyingTypeUInt64, (Enum)Enum.Parse(EnumType, v, true), culture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ internal sealed class XDRSchema : XMLSchema
internal string _schemaUri;
internal XmlElement _schemaRoot;
internal DataSet _ds;
private static readonly char[] s_colonArray = new char[] { ':' };

internal XDRSchema(DataSet ds, bool fInline)
{
Expand Down Expand Up @@ -294,7 +293,7 @@ private static NameType FindNameType(string name)
private Type ParseDataType(string dt, string dtValues)
{
string strType = dt;
string[] parts = dt.Split(s_colonArray); // ":"
string[] parts = dt.Split(':');

if (parts.Length > 2)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace System.Diagnostics
{
public sealed partial class FileVersionInfo
{
private static readonly char[] s_versionSeparators = new char[] { '.' };

private FileVersionInfo(string fileName)
{
_fileName = fileName;
Expand Down Expand Up @@ -204,7 +202,7 @@ private static void ParseVersion(string? versionString, out int major, out int m

if (versionString != null)
{
string[] parts = versionString.Split(s_versionSeparators);
string[] parts = versionString.Split('.');
if (parts.Length <= 4 && parts.Length > 0)
{
major = ParseUInt16UntilNonDigit(parts[0], out bool endedEarly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ internal static void LoadPrinterResolutions(string printer, PrinterSettings sett
int x_resolution, y_resolution;
try
{
if (resolution.Contains("x")) // string.Contains(char) is .NetCore2.1+ specific
if (resolution.Contains('x'))
{
string[] resolutions = resolution.Split(new[] { 'x' });
string[] resolutions = resolution.Split('x');
x_resolution = Convert.ToInt32(resolutions[0]);
y_resolution = Convert.ToInt32(resolutions[1]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public class CryptoConfig
private static readonly ConcurrentDictionary<string, Type> appNameHT = new ConcurrentDictionary<string, Type>(StringComparer.OrdinalIgnoreCase);
private static readonly ConcurrentDictionary<string, string> appOidHT = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

private static readonly char[] SepArray = { '.' }; // valid ASN.1 separators

// .NET Core does not support AllowOnlyFipsAlgorithms
public static bool AllowOnlyFipsAlgorithms => false;

Expand Down Expand Up @@ -503,7 +501,7 @@ public static byte[] EncodeOID(string str)
if (str == null)
throw new ArgumentNullException(nameof(str));

string[] oidString = str.Split(SepArray);
string[] oidString = str.Split('.'); // valid ASN.1 separator
uint[] oidNums = new uint[oidString.Length];
for (int i = 0; i < oidString.Length; i++)
{
Expand Down