Skip to content

Commit 5a8f405

Browse files
authored
Use Contains{Any} in Regex source generator (#112065)
1 parent e51af40 commit 5a8f405

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,11 +4079,13 @@ void EmitSingleCharRepeater(RegexNode node, bool emitLengthCheck = true)
40794079

40804080
// If we're able to vectorize the search, do so. Otherwise, fall back to a loop.
40814081
// For the loop, we're validating that each char matches the target node.
4082-
// For IndexOf, we're looking for the first thing that _doesn't_ match the target node,
4082+
// For Contains{Any}, we're looking for the first thing that _doesn't_ match the target node,
40834083
// and thus similarly validating that everything does.
40844084
if (TryEmitIndexOf(requiredHelpers, node, useLast: false, negate: true, out _, out string? indexOfExpr))
40854085
{
4086-
using (EmitBlock(writer, $"if ({sliceSpan}.Slice({sliceStaticPos}, {iterations}).{indexOfExpr} >= 0)"))
4086+
string containsExpr = indexOfExpr.Replace("IndexOf", "Contains");
4087+
4088+
using (EmitBlock(writer, $"if ({sliceSpan}.Slice({sliceStaticPos}, {iterations}).{containsExpr})"))
40874089
{
40884090
Goto(doneLabel);
40894091
}

0 commit comments

Comments
 (0)