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

Replace some single-char strings with chars #81831

Merged
merged 3 commits into from
Feb 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private static void SplitTypeName(string fullname, out string name, out string n
Debug.Assert(fullname != null);

// Get namespace
int nsDelimiter = fullname.LastIndexOf(".", StringComparison.Ordinal);
int nsDelimiter = fullname.LastIndexOf('.');
if (nsDelimiter != -1)
{
ns = fullname.Substring(0, nsDelimiter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal static string ComputeParametersString(RuntimeParameterInfo[] parameters
// Legacy: Why use "ByRef" for by ref parameters? What language is this?
// VB uses "ByRef" but it should precede (not follow) the parameter name.
// Why don't we just use "&"?
if (parameterTypeString.EndsWith("&"))
if (parameterTypeString.EndsWith('&'))
{
sb.Append(parameterTypeString, 0, parameterTypeString.Length - 1);
sb.Append(" ByRef");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed override MemberInfo[] GetMember(string name, MemberTypes type, Bin

private MemberInfo[] GetMemberImpl(string optionalNameOrPrefix, MemberTypes type, BindingFlags bindingAttr)
{
bool prefixSearch = optionalNameOrPrefix != null && optionalNameOrPrefix.EndsWith("*", StringComparison.Ordinal);
bool prefixSearch = optionalNameOrPrefix != null && optionalNameOrPrefix.EndsWith('*');
string? optionalName = prefixSearch ? null : optionalNameOrPrefix;

Func<MemberInfo, bool>? predicate = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,11 @@ private static bool InitializeDefaultActivityIdFormat()
string? switchValue = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_DIAGNOSTICS_DEFAULTACTIVITYIDFORMATISHIERARCHIAL");
if (switchValue != null)
{
defaultActivityIdFormatIsHierarchial = IsTrueStringIgnoreCase(switchValue) || switchValue.Equals("1");
defaultActivityIdFormatIsHierarchial = switchValue.Equals("true", StringComparison.OrdinalIgnoreCase) || switchValue.Equals("1");
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
}
}

return defaultActivityIdFormatIsHierarchial;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsTrueStringIgnoreCase(string value)
{
return value.Length == 4 &&
(value[0] == 't' || value[0] == 'T') &&
(value[1] == 'r' || value[1] == 'R') &&
(value[2] == 'u' || value[2] == 'U') &&
(value[3] == 'e' || value[3] == 'E');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ private static ProcessInfo[] GetProcessInfos(PerformanceCounterLib library, int
// at the end. If instanceName ends in ".", ".e", or ".ex" we remove it.
if (instanceName.Length == 15)
{
if (instanceName.EndsWith(".", StringComparison.Ordinal))
if (instanceName.EndsWith("."))
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
{
instanceName = instanceName.Slice(0, 14);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen(
ValueStringBuilder sb = default;
sb.Append(font.Name);
sb.Append(culture.TextInfo.ListSeparator[0]);
sb.Append(" ");
sb.Append(' ');
sb.Append(font.Size.ToString(culture.NumberFormat));

switch (font.Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ public static string[] BuildServiceNames(string uriPrefix)
{
string hostname = ExtractHostname(uriPrefix, true)!;

if (string.Equals(hostname, "*", StringComparison.OrdinalIgnoreCase) ||
string.Equals(hostname, "+", StringComparison.OrdinalIgnoreCase) ||
if (hostname == "*" ||
hostname == "+" ||
IPAddress.TryParse(hostname, out _))
{
// for a wildcard, register the machine name. If the caller doesn't have DNS permission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,8 @@ private static void SendError(HttpListenerSession session, ulong requestId, Http
httpResponse.pReason = (sbyte*)pReason;
httpResponse.ReasonLength = (ushort)byteReason.Length;

byte[] byteContentLength = Encoding.Default.GetBytes("0");
fixed (byte* pContentLength = &byteContentLength[0])
ReadOnlySpan<byte> byteContentLength = "0"u8;
fixed (byte* pContentLength = byteContentLength)
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
{
(&httpResponse.Headers.KnownHeaders)[(int)HttpResponseHeader.ContentLength].pRawValue = (sbyte*)pContentLength;
(&httpResponse.Headers.KnownHeaders)[(int)HttpResponseHeader.ContentLength].RawValueLength = (ushort)byteContentLength.Length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal static short GetInt16Config(string configName, short defaultValue, bool
{
result = Convert.ToInt16(str, 16);
}
else if (str.StartsWith("0"))
else if (str.StartsWith('0'))
{
result = Convert.ToInt16(str, 8);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static IEnumerable<LibraryNameVariation> DetermineLibraryNameVariations
yield return new LibraryNameVariation(string.Empty, string.Empty);

if (isRelativePath
&& !libName.EndsWith(".", StringComparison.OrdinalIgnoreCase)
&& !libName.EndsWith('.')
&& !libName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
&& !libName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private void ParseGrammar(XmlReader reader, IGrammar grammar)
catch (ArgumentException)
{
// Unknown Culture info, fall back to the base culture.
int pos = reader.Value.IndexOf("-", StringComparison.Ordinal);
int pos = reader.Value.IndexOf('-');
if (pos > 0)
{
grammar.Culture = _langId = new CultureInfo(reader.Value.Substring(0, pos));
Expand Down Expand Up @@ -1767,7 +1767,7 @@ private static void SetRepeatValues(string repeat, out int minRepeat, out int ma
minRepeat = maxRepeat = 1;
if (!string.IsNullOrEmpty(repeat))
{
int sep = repeat.IndexOf("-", StringComparison.Ordinal);
int sep = repeat.IndexOf('-');

if (sep < 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void ProcessSpeakElement(XmlReader reader, ISsmlParser engine, ob
{
innerException = e;
// Unknown Culture info, fall back to the base culture.
int pos = reader.Value.IndexOf("-", StringComparison.Ordinal);
int pos = reader.Value.IndexOf('-');
if (pos > 0)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private static void SplitName(string? fullname, out string? name, out string? ns
return;

// Get namespace
int nsDelimiter = fullname.LastIndexOf(".", StringComparison.Ordinal);
int nsDelimiter = fullname.LastIndexOf('.');
if (nsDelimiter != -1)
{
ns = fullname.Substring(0, nsDelimiter);
Expand Down Expand Up @@ -236,7 +236,7 @@ private static void FilterHelper(
listType = MemberListType.CaseSensitive;
}

if (allowPrefixLookup && name.EndsWith("*", StringComparison.Ordinal))
if (allowPrefixLookup && name.EndsWith('*'))
{
// We set prefixLookup to true if name ends with a "*".
// We will also set listType to All so that all members are included in
Expand Down