Skip to content

Commit

Permalink
Expand an optimization for short values to IgnoreCase in single-value…
Browse files Browse the repository at this point in the history
… SearchValues<string>
  • Loading branch information
MihaZupan committed Sep 29, 2024
1 parent ba9b3ba commit 1f386bf
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ private bool TryMatch(ref char searchSpaceStart, int searchSpaceLength, ref char
// If the value is short (!TValueLength.AtLeast4Chars => 2 or 3 characters), the anchors already represent the whole value.
// With case-sensitive comparisons, we've therefore already confirmed the match, so we can skip doing so here.
// With case-insensitive comparisons, we applied a mask to the input, so while the anchors likely matched, we can't be sure.
if ((typeof(TCaseSensitivity) == typeof(CaseSensitive) && !TValueLength.AtLeast4Chars) ||
// If the value is composed of only ASCII letters, masking the input can't produce false positives, so we can also skip the verification step.
if (((typeof(TCaseSensitivity) == typeof(CaseSensitive) || typeof(TCaseSensitivity) == typeof(CaseInsensitiveAsciiLetters)) && !TValueLength.AtLeast4Chars) ||
TCaseSensitivity.Equals<TValueLength>(ref matchRef, _value))
{
offsetFromStart = (int)((nuint)Unsafe.ByteOffset(ref searchSpaceStart, ref matchRef) / 2);
Expand Down Expand Up @@ -362,7 +363,8 @@ private bool TryMatch(ref char searchSpaceStart, int searchSpaceLength, ref char
// If the value is short (!TValueLength.AtLeast4Chars => 2 or 3 characters), the anchors already represent the whole value.
// With case-sensitive comparisons, we've therefore already confirmed the match, so we can skip doing so here.
// With case-insensitive comparisons, we applied a mask to the input, so while the anchors likely matched, we can't be sure.
if ((typeof(TCaseSensitivity) == typeof(CaseSensitive) && !TValueLength.AtLeast4Chars) ||
// If the value is composed of only ASCII letters, masking the input can't produce false positives, so we can also skip the verification step.
if (((typeof(TCaseSensitivity) == typeof(CaseSensitive) || typeof(TCaseSensitivity) == typeof(CaseInsensitiveAsciiLetters)) && !TValueLength.AtLeast4Chars) ||
TCaseSensitivity.Equals<TValueLength>(ref matchRef, _value))
{
offsetFromStart = (int)((nuint)Unsafe.ByteOffset(ref searchSpaceStart, ref matchRef) / 2);
Expand Down

0 comments on commit 1f386bf

Please sign in to comment.