Skip to content
Open
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 @@ -36,7 +36,7 @@ public int CompareTo(EcmaModule other)
// Multi-module assembly: compare two modules that are part of same assembly
string thisName = _metadataReader.GetString(_metadataReader.GetModuleDefinition().Name);
string otherName = other._metadataReader.GetString(other._metadataReader.GetModuleDefinition().Name);
Debug.Assert(StringComparer.Ordinal.Compare(thisName, otherName) != 0);
Debug.Assert(!StringComparer.Ordinal.Equals(thisName, otherName));
return StringComparer.Ordinal.Compare(thisName, otherName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public AssemblyQualifiedToken(IMemberDefinition member) =>
public override int GetHashCode() => AssemblyName == null ? 0 : AssemblyName.GetHashCode() ^ Token.GetHashCode();
public override string ToString() => $"{AssemblyName}: {Token}";
public bool Equals(AssemblyQualifiedToken other) =>
string.CompareOrdinal(AssemblyName, other.AssemblyName) == 0 && Token == other.Token;
AssemblyName == other.AssemblyName && Token == other.Token;
public override bool Equals([NotNullWhen(true)] object? obj) => ((AssemblyQualifiedToken?)obj)?.Equals(this) == true;

public bool IsNil => AssemblyName == null;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/tools/dotnet-pgo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ internal static void UnZipIfNecessary(ref string inputFileName, TextWriter log)
}

var extension = Path.GetExtension(inputFileName);
if (string.Compare(extension, ".zip", StringComparison.OrdinalIgnoreCase) == 0 ||
string.Compare(extension, ".vspx", StringComparison.OrdinalIgnoreCase) == 0)
if (string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) ||
string.Equals(extension, ".vspx", StringComparison.OrdinalIgnoreCase))
{
string unzipedEtlFile;
if (inputFileName.EndsWith(".etl.zip", StringComparison.OrdinalIgnoreCase))
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/Net/CredentialCacheKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private bool IsPrefix(Uri uri, int prefixLen)
return false;
}

return string.Compare(uri.AbsolutePath, 0, uriPrefix.AbsolutePath, 0, UriPrefixLength, StringComparison.OrdinalIgnoreCase) == 0;
return uri.AbsolutePath.AsSpan(0, UriPrefixLength).Equals(uriPrefix.AbsolutePath.AsSpan(0, UriPrefixLength), StringComparison.OrdinalIgnoreCase);
}

public override int GetHashCode() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,9 @@ private void ApplyResources(object value, Type typeFromValue, string objectName,
// See if this key matches our object.
string key = kvp.Key;

if (IgnoreCase)
if (!key.StartsWith(objectName, IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))
{
if (string.Compare(key, 0, objectName, 0, objectName.Length, StringComparison.OrdinalIgnoreCase) != 0)
{
continue;
}
}
else
{
if (string.CompareOrdinal(key, 0, objectName, 0, objectName.Length) != 0)
{
continue;
}
continue;
}

// Character after objectName.Length should be a "." or a '-', or else we should continue.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public DesignerOptionCollection? this[string name]
EnsurePopulated();
foreach (DesignerOptionCollection child in _children)
{
if (string.Compare(child.Name, name, true, CultureInfo.InvariantCulture) == 0)
if (string.Equals(child.Name, name, StringComparison.InvariantCultureIgnoreCase))
{
return child;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ protected override void FillAttributes(IList attributes)
internal void OnINotifyPropertyChanged(object? component, PropertyChangedEventArgs e)
{
if (string.IsNullOrEmpty(e.PropertyName) ||
string.Compare(e.PropertyName, Name, true, CultureInfo.InvariantCulture) == 0)
string.Equals(e.PropertyName, Name, StringComparison.InvariantCultureIgnoreCase))
{
OnValueChanged(component, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static int GetNoneNesting(string val)
{
count++;
}
if (count > 0 && string.Compare(NullString, 0, val, count, len - 2 * count, StringComparison.Ordinal) != 0)
if (count > 0 && !val.AsSpan(count, len - 2 * count).Equals(NullString, StringComparison.Ordinal))
{
// the stuff between the parens is not "None"
count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ internal static bool EqualsIgnoreCase(string s1, string s2)

internal static bool StartsWithOrdinal(string s1, string s2)
{
if (s2 == null) return false;
return 0 == string.Compare(s1, 0, s2, 0, s2.Length, StringComparison.Ordinal);
if (s1 is null || s2 is null) return false;
return s1.StartsWith(s2, StringComparison.Ordinal);
}

internal static bool StartsWithOrdinalIgnoreCase(string s1, string s2)
{
if (s2 == null) return false;
return 0 == string.Compare(s1, 0, s2, 0, s2.Length, StringComparison.OrdinalIgnoreCase);
if (s1 is null || s2 is null) return false;
return s1.StartsWith(s2, StringComparison.OrdinalIgnoreCase);
}

internal static string[] ObjectArrayToStringArray(object[] objectArray)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static bool IsEqualOrSubdirectory(string dir, string subdir)
if (lSubdir < lDir)
return false;

if (string.Compare(dir, 0, subdir, 0, lDir, StringComparison.OrdinalIgnoreCase) != 0)
if (!dir.AsSpan(0, lDir).Equals(subdir.AsSpan(0, lDir), StringComparison.OrdinalIgnoreCase))
return false;

// Check subdir that character following length of dir is a backslash
Expand Down Expand Up @@ -84,7 +84,7 @@ private static bool IsEqualOrSubpathImpl(string path, string subpath, bool exclu
if (excludeEqual && (lSubpath == lPath))
return false;

if (string.Compare(path, 0, subpath, 0, lPath, StringComparison.OrdinalIgnoreCase) != 0)
if (!path.AsSpan(0, lPath).Equals(subpath.AsSpan(0, lPath), StringComparison.OrdinalIgnoreCase))
return false;

// Check subpath that character following length of path is a slash
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Data.Common/src/System/Data/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3717,11 +3717,11 @@ internal IndexField[] ParseSortString(string? sortString)
// handle ASC and DESC.
int length = current.Length;
bool descending = false;
if (length >= 5 && string.Compare(current, length - 4, " ASC", 0, 4, StringComparison.OrdinalIgnoreCase) == 0)
if (length >= 5 && current.EndsWith(" ASC", StringComparison.OrdinalIgnoreCase))
{
current = current.AsSpan(0, length - 4).Trim().ToString();
}
else if (length >= 6 && string.Compare(current, length - 5, " DESC", 0, 5, StringComparison.OrdinalIgnoreCase) == 0)
else if (length >= 6 && current.EndsWith(" DESC", StringComparison.OrdinalIgnoreCase))
{
descending = true;
current = current.AsSpan(0, length - 5).Trim().ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ internal bool StartsWith(string tokenString)
return false;
}

if (0 == string.Compare(_sqlstatement, tempidx, tokenString, 0, tokenString.Length, StringComparison.OrdinalIgnoreCase))
if (_sqlstatement.AsSpan(tempidx).StartsWith(tokenString, StringComparison.OrdinalIgnoreCase))
{
// Reset current position and token
_idx = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public static void DeleteEventSource(string source, string machineName)
// The reason: each log registry key must always contain subkey (i.e. source) with the same name.
string keyname = key.Name;
int index = keyname.LastIndexOf('\\');
if (string.Compare(keyname, index + 1, source, 0, keyname.Length - index, StringComparison.Ordinal) == 0)
if (keyname.AsSpan(index + 1).Equals(source, StringComparison.Ordinal))
throw new InvalidOperationException(SR.Format(SR.CannotDeleteEqualSource, source));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string? parti
// multivalues attribute we can stop here.
foundPartitionEntry = true;

if (string.Compare(dnString, 10, "0", 0, 1, StringComparison.OrdinalIgnoreCase) == 0)
if (dnString[10] == '0')
{
// this server has the partition fully instantiated
ntdsaNames.Add(ntdsaName);
Expand Down Expand Up @@ -1648,7 +1648,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string? parti
// find the property name with the range info
foreach (string property in res.Properties.PropertyNames)
{
if (string.Compare(property, 0, PropertyManager.MsDSHasInstantiatedNCs, 0, PropertyManager.MsDSHasInstantiatedNCs.Length, StringComparison.OrdinalIgnoreCase) == 0)
if (property.AsSpan().StartsWith(PropertyManager.MsDSHasInstantiatedNCs, StringComparison.OrdinalIgnoreCase))
{
propertyName = property;
break;
Expand Down Expand Up @@ -1677,7 +1677,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string? parti
{
foundPartitionEntry = true;

if (string.Compare(dnString, 10, "0", 0, 1, StringComparison.OrdinalIgnoreCase) == 0)
if (dnString[10] == '0')
{
ntdsaNames.Add(ntdsaName);
if (isADAM)
Expand Down
Loading
Loading