-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Remove some unnecessary slicing from generated Regex code #61701
Conversation
When we're outputting code to match a "multi" (a sequence of multiple characters), we're currently issuing a Slice for the known tracked offset even if that offset is 0. We can skip that nop.
Tagging subscribers to this area: @eerhardt, @dotnet/area-system-text-regularexpressions Issue DetailsWhen we're outputting code to match a "multi" (a sequence of multiple characters), we're currently issuing a Slice for the known tracked offset even if that offset is 0. We can skip that nop. cc: @joperezr, @danmoseley Matching "defg" as part of a pattern before// Multi "defg"
{
byteSpan = global::System.Runtime.InteropServices.MemoryMarshal.AsBytes(textSpan);
if ((uint)textSpan.Length < 4 ||
global::System.Buffers.Binary.BinaryPrimitives.ReadUInt64LittleEndian(byteSpan.Slice(0)) != 0x67006600650064ul)
{
goto NoMatch;
}
} Matching "defg" as part of a pattern after// Multi "defg"
{
byteSpan = global::System.Runtime.InteropServices.MemoryMarshal.AsBytes(textSpan);
if ((uint)textSpan.Length < 4 ||
global::System.Buffers.Binary.BinaryPrimitives.ReadUInt64LittleEndian(byteSpan) != 0x67006600650064ul)
{
goto NoMatch;
}
}
|
src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs
Show resolved
Hide resolved
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.
Other than the one comment this looks good. Is it worth adding a unit test that ensures the Slice is not there in this case? (if the tiny optimization doesn't warrant a test that's ok too)
This would likely manifest as a test which generated code and compared the generated output to a known string. We currently don't have any such tests. We could certainly add some (separately), though they would likely be a non-trivial time sink until the code has stabilized further, as many changes would likely require regenerating all such pre-generated snippets. |
When we're outputting code to match a "multi" (a sequence of multiple characters), we're currently issuing a Slice for the known tracked offset even if that offset is 0. We can skip that nop.
cc: @joperezr, @danmoseley
Matching "defg" as part of a pattern before
Matching "defg" as part of a pattern after