Skip to content

Commit

Permalink
Call String.Contains(char) from String.Contains(string) for single-ch…
Browse files Browse the repository at this point in the history
…ar literals (#97632)
  • Loading branch information
EgorBo authored Jan 29, 2024
1 parent 3eabd9a commit 9025846
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public bool Contains(string value)
if (value == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);

if (RuntimeHelpers.IsKnownConstant(value) && value.Length == 1)
{
// Call the char overload, e.g. Contains("X") -> Contains('X')
return Contains(value[0]);
}

return SpanHelpers.IndexOf(
ref _firstChar,
Length,
Expand Down

0 comments on commit 9025846

Please sign in to comment.