Skip to content
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

Adding Regex.IsMatch(Span) and RegexRunner.Scan() methods #65473

Merged
merged 18 commits into from
Feb 26, 2022

Conversation

joperezr
Copy link
Member

@joperezr joperezr commented Feb 17, 2022

Fixes #59629

This is mainly superseding #62509 now that the APIs have been approved. I have addressed most of the comments from @stephentoub there except for two things which I plan to do in this PR by adding one more commit which are:

  • Implement Regex.Run on top of Regex.Run in order to avoid duplication.
  • For most of the tests where we are testing isMatch with string, also call in the isMatch(span) new methods to get test coverage into the new surface area.

While I add the above two bullets into a commit, I thought of pushing this PR as it is ready for review other than those two things.

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Feb 17, 2022

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #59629

This is mainly superseding #62509 now that the APIs have been approved. I have addressed most of the comments from @stephentoub there except for two things which I plan to do in this PR by adding one more commit which are:

  • Implement Regex.Run on top of Regex.Run in order to avoid duplication.
  • For most of the tests where we are testing isMatch with string, also call in the isMatch(span) new methods to get test coverage into the new surface area.

While I add the above two bullets into a commit, I thought of pushing this PR as it is ready for review other than those two things.

Author: joperezr
Assignees: -
Labels:

area-System.Text.RegularExpressions, new-api-needs-documentation

Milestone: -

Comment on lines 190 to 213
// Everything below runs once per runner.

InitTrackCount();

int stacksize;
int tracksize = stacksize = runtrackcount * 8;

if (tracksize < 32)
{
tracksize = 32;
}
if (stacksize < 16)
{
stacksize = 16;
}

runtrack = new int[tracksize];
runtrackpos = tracksize;

runstack = new int[stacksize];
runstackpos = stacksize;

runcrawl = new int[32];
runcrawlpos = 32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to do it now, but we're going to want to revisit this logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume what you are thinking is only do this initialization if the current runner is Interpreted right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially. We only need to initialize runtrack if the runner is interpreted. We need runstack for Compiled and the source generator as well, but not for NonBacktracking, and the size is also based off of runtrackcount which is largely irrelevant, so we need to figure out what the right default size should be. runcrawl is only relevant if there are captures, so it's very likely the default size chosen here is too large.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting close :)

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more mostly small comments to be addressed.

Other than that, LGTM. Thanks!

@joperezr
Copy link
Member Author

The remaining failure is unrelated to this PR, So I’ll go ahead and merge. I will also log an issue for that failure in case there isn’t one yet.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Augment Regex extensibility point for better perf and span-based matching
2 participants