-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify code emitted for single char repeater #62322
Conversation
Rather than outputting an if block per unrolled iteration, just output a clause for each iteration as part of a single if block. We already do this for concatenations, but we don't yet for standalone repeaters.
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue DetailsRather than outputting an if block per unrolled iteration, just output a clause for each iteration as part of a single if block. We already do this for concatenations, but we don't yet for standalone repeaters. e.g. for the expression if ((uint)textSpan.Length < 3)
{
goto NoMatch;
}
if (!char.IsDigit(textSpan[0]))
{
goto NoMatch;
}
if (!char.IsDigit(textSpan[1]))
{
goto NoMatch;
}
if (!char.IsDigit(textSpan[2]))
{
goto NoMatch;
} and now we'll output if ((uint)textSpan.Length < 3 ||
!char.IsDigit(textSpan[0]) ||
!char.IsDigit(textSpan[1]) ||
!char.IsDigit(textSpan[2]))
{
goto NoMatch;
} cc: @joperezr
|
{ | ||
EmitSingleChar(node, emitLengthCheck: false); | ||
writer.WriteLine($"{SpanLengthCheck(iterations)} ||"); | ||
writer.Write(" "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an aside comment, I've seen in some places in the emitter we just do:
writer.Indent += 4;
// .. your indented writes
writer.Indent -= 4;
And we also have few places where we just write the spaces manually. If you agree, I'm happy to put up a PR that just normalizes to always use the Indent property to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with whichever is more readable and maintainable. Places that currently manually indent looked subjectively better to my eyes, but it can be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Rather than outputting an if block per unrolled iteration, just output a clause for each iteration as part of a single if block. We already do this for concatenations, but we don't yet for standalone repeaters.
e.g. for the expression
\d{3}
, previously we would have output:and now we'll output
cc: @joperezr