Skip to content

Commit

Permalink
string.EndsWith use SequenceEqual not SequenceCompareTo (dotnet#22207)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored and jkotas committed Jan 28, 2019
1 parent 87cc716 commit 57fd77e
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ public bool EndsWith(string value, StringComparison comparisonType)
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);
Expand Down

0 comments on commit 57fd77e

Please sign in to comment.