Skip to content

Conversation

@stephentoub
Copy link
Member

cc: @joperezr

@ghost
Copy link

ghost commented Dec 6, 2021

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

Issue Details

cc: @joperezr

Author: stephentoub
Assignees: -
Labels:

area-System.Text.RegularExpressions

Milestone: -

The expression "(?!)" (an empty negative lookahead) is sometimes used in expressions at a point where we want to match nothing and thus fail a match, often in combination with a conditional operation.  This negative lookahead wrapped around an empty can be reduced to simply a Nothing, which is cheaper to process.
We currently output goto-based code, avoiding an actual if/else construct in case the child branches need to backtrack (and with the forced scoping for the if/else blocks, backtracking would result in compilation failures due to trying to jump to labels defined inside those scopes).  But if we know in advance that no such backtracking will happen, we can output the nicer if/else code.
We were iterating through each individual character in our own open-coded loop, but for case-sensitive, we can just delegate to SequenceEqual.
Rather than wrapping a node in a new positive lookahead assertion node, just call the logic to emit the node as if it were a positive lookahead.
@stephentoub stephentoub merged commit 9e8e4fc into dotnet:main Dec 6, 2021
@stephentoub stephentoub deleted the moreregexopt branch December 6, 2021 20:41
@ghost ghost locked as resolved and limited conversation to collaborators Jan 6, 2022
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.

3 participants