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

Change RegexCompiler to special-case sets of just 2 or 3 chars #31734

Merged
merged 2 commits into from
Feb 5, 2020

Conversation

stephentoub
Copy link
Member

When we need to emit the code to match a character against a set, we call a helper that checks lots of conditions and determines the best code to output for that check, e.g. if the set is '\d', we just emit a call to char.IsDigit, or if the set contains a single range, we emit a simple range check. It turns out it's common to have sets with just two or three characters in them, in particular coming from our prefix checker that, e.g. for a global alternation, will generate a set containing the first possible characters of each branch. In master we generate a lookup table for such a set, but that involves computing the bit offset from the lookup table, doing the appropriate shifts, indexing, etc.; for two or three characters, it's cheaper to just perform the two or three comparison operations. For example, this makes a few percent improvement on regex redux, where we end up doing lots of these comparisons.

cc: @danmosemsft, @eerhardt, @ViktorHofer

Copy link
Contributor

@pgovind pgovind left a comment

Choose a reason for hiding this comment

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

Ship it

Co-Authored-By: Dan Moseley <danmose@microsoft.com>
@stephentoub stephentoub merged commit 95b361d into dotnet:master Feb 5, 2020
@stephentoub stephentoub deleted the codegen23 branch February 5, 2020 14:46
@ghost ghost added the will_lock_this label Dec 6, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 5, 2021
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.

4 participants