diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexFindOptimizations.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexFindOptimizations.cs index 1318769136235..1291dff977e9f 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexFindOptimizations.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexFindOptimizations.cs @@ -84,7 +84,6 @@ public RegexFindOptimizations(RegexNode root, RegexOptions options) bool dfa = (options & RegexOptions.NonBacktracking) != 0; bool compiled = (options & RegexOptions.Compiled) != 0 && !dfa; // for now, we never generate code for NonBacktracking, so treat it as non-compiled bool interpreter = !compiled && !dfa; - bool usesRfoTryFind = !compiled; // For interpreter, we want to employ optimizations, but we don't want to make construction significantly // more expensive; someone who wants to pay to do more work can specify Compiled. So for the interpreter @@ -149,10 +148,7 @@ public RegexFindOptimizations(RegexNode root, RegexOptions options) LeadingPrefixes = caseInsensitivePrefixes; FindMode = FindNextStartingPositionMode.LeadingStrings_OrdinalIgnoreCase_LeftToRight; #if SYSTEM_TEXT_REGULAREXPRESSIONS - if (usesRfoTryFind) - { - LeadingStrings = SearchValues.Create(LeadingPrefixes, StringComparison.OrdinalIgnoreCase); - } + LeadingStrings = SearchValues.Create(LeadingPrefixes, StringComparison.OrdinalIgnoreCase); #endif return; } @@ -165,10 +161,7 @@ public RegexFindOptimizations(RegexNode root, RegexOptions options) // LeadingPrefixes = caseSensitivePrefixes; // FindMode = FindNextStartingPositionMode.LeadingStrings_LeftToRight; #if SYSTEM_TEXT_REGULAREXPRESSIONS - // if (usesRfoTryFind) - // { - // LeadingStrings = SearchValues.Create(LeadingPrefixes, StringComparison.Ordinal); - // } + // LeadingStrings = SearchValues.Create(LeadingPrefixes, StringComparison.Ordinal); #endif // return; //} @@ -699,14 +692,9 @@ public bool TryFindNextStartingPositionLeftToRight(ReadOnlySpan textSpan, case FindNextStartingPositionMode.LeadingStrings_LeftToRight: case FindNextStartingPositionMode.LeadingStrings_OrdinalIgnoreCase_LeftToRight: { - if (LeadingStrings is not SearchValues searchValues) - { - // This should be exceedingly rare and only happen if a Compiled regex selected this - // option but then failed to compile (e.g. due to too deep stacks) and fell back to the interpreter. - return true; - } + Debug.Assert(LeadingStrings is not null); - int i = textSpan.Slice(pos).IndexOfAny(searchValues); + int i = textSpan.Slice(pos).IndexOfAny(LeadingStrings); if (i >= 0) { pos += i;