You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve choice of IndexOfXx routine for some TryFindNextStartingPosition implementations (#89099)
Earlier in .NET 8, we updated the Regex compiler and source generator to be able to vectorize a search for any set, not just simple ones. When one of the main routines couldn't be used, we emit a specialized IndexOfAny helper that uses SearchValues to search for any matching ASCII character or a Unicode character, and if it encounters a Unicode character, it falls back to a linear scan. This meant that a bunch of sets that wouldn't previously have taken these paths now do, but some of those sets have more efficient means of searching; for example, for the set `[^aA]` that searches case-insensitive for anything other than an 'A', with these scheme we'll emit a whole routine that uses SearchValues with a fallback, but we could just use IndexOfAnyExcept('A', 'a'). This fixes the compiler / source generator to prefer such helpers instead when available.
subsequent?.FindStartingLiteral(4)isRegexNode.StartingLiteralDataliteral&&// 5 == max optimized by IndexOfAny, and we need to reserve 1 for node.Ch
3335
+
subsequent?.FindStartingLiteral(4)isRegexNode.StartingLiteralDataliteral&&// 5 == max efficiently optimized by IndexOfAny, and we need to reserve 1 for node.Ch
3311
3336
!literal.Negated&&// not negated; can't search for both the node.Ch and a negated subsequent char with an IndexOf* method
Copy file name to clipboardExpand all lines: src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1419,7 +1419,7 @@ public char FirstCharOfOneOrMulti()
1419
1419
/// A tuple of data about the literal: only one of the Char/String/SetChars fields is relevant.
1420
1420
/// The Negated value indicates whether the Char/SetChars should be considered exclusionary.
1421
1421
/// </returns>
1422
-
publicStartingLiteralData?FindStartingLiteral(intmaxSetCharacters=5)// 5 is max optimized by IndexOfAny today
1422
+
publicStartingLiteralData?FindStartingLiteral(intmaxSetCharacters=5)// 5 is max efficiently optimized by IndexOfAny today
1423
1423
{
1424
1424
Debug.Assert(maxSetCharacters>=0&&maxSetCharacters<=128,$"{nameof(maxSetCharacters)} == {maxSetCharacters} should be small enough to be stack allocated.");
0 commit comments