string.EndsWith use SequenceEqual not SequenceCompareTo (dotnet/coreclr#22207)
authorBen Adams <thundercat@illyriad.co.uk>
Mon, 28 Jan 2019 02:29:19 +0000 (03:29 +0100)
committerJan Kotas <jkotas@microsoft.com>
Mon, 28 Jan 2019 02:29:19 +0000 (18:29 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/57fd77e6f8f7f2c37cc5c3b36df3ea4f302e143b

src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs

index c8f0d20..4b8a160 100644 (file)
@@ -566,7 +566,8 @@ namespace System
                     return CompareInfo.Invariant.IsSuffix(this, value, GetCaseCompareOfComparisonCulture(comparisonType));
 
                 case StringComparison.Ordinal:
-                    return this.Length < value.Length ? false : (CompareOrdinalHelper(this, this.Length - value.Length, value.Length, value, 0, value.Length) == 0);
+                    int offset = this.Length - value.Length;
+                    return (uint)offset <= (uint)this.Length && this.AsSpan(offset).SequenceEqual(value);
 
                 case StringComparison.OrdinalIgnoreCase:
                     return this.Length < value.Length ? false : (CompareInfo.CompareOrdinalIgnoreCase(this, this.Length - value.Length, value.Length, value, 0, value.Length) == 0);