Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

string.EndsWith use SequenceEqual not SequenceCompareTo #22207

Merged
merged 5 commits into from
Jan 28, 2019
Merged
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 @@ -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