Skip to content

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

2 participants