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

Commit 57fd77e

Browse files
benaadamsjkotas
authored andcommitted
string.EndsWith use SequenceEqual not SequenceCompareTo (#22207)
1 parent 87cc716 commit 57fd77e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ public bool EndsWith(string value, StringComparison comparisonType)
566566
return CompareInfo.Invariant.IsSuffix(this, value, GetCaseCompareOfComparisonCulture(comparisonType));
567567

568568
case StringComparison.Ordinal:
569-
return this.Length < value.Length ? false : (CompareOrdinalHelper(this, this.Length - value.Length, value.Length, value, 0, value.Length) == 0);
569+
int offset = this.Length - value.Length;
570+
return (uint)offset <= (uint)this.Length && this.AsSpan(offset).SequenceEqual(value);
570571

571572
case StringComparison.OrdinalIgnoreCase:
572573
return this.Length < value.Length ? false : (CompareInfo.CompareOrdinalIgnoreCase(this, this.Length - value.Length, value.Length, value, 0, value.Length) == 0);

0 commit comments

Comments
 (0)