Skip to content

[swift/main] Optimize search for start-anchored regexes #683

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

Merged

Conversation

natecook1000
Copy link
Member

@natecook1000 natecook1000 commented Jul 19, 2023

When a regex is anchored to the start of a subject, there's no need to search throughout a string for the pattern when searching for the first match: a prefix match is sufficient.

This adds a regex compilation-time check about whether a match can only be found at the start of a subject, and then uses that to choose whether to defer to prefixMatch from within firstMatch.

(This is a cherry-pick of #682.)

When a regex is anchored to the start of a subject, there's no need
to search throughout a string for the pattern when searching for the
first match: a prefix match is sufficient.

This adds a regex compilation-time check about whether a match can
only be found at the start of a subject, and then uses that to
choose whether to defer to `prefixMatch` from within `firstMatch`.
@natecook1000 natecook1000 changed the title Optimize search for start-anchored regexes (#682) [swift/main] Optimize search for start-anchored regexes Jul 19, 2023
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit cc96bb5 into swiftlang:swift/main Jul 20, 2023
@natecook1000 natecook1000 deleted the anchor_prefix_match_main branch July 20, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants