swiftlang / swift-experimental-string-processing

An early experimental general-purpose pattern matching engine for Swift.
Apache License 2.0
278 stars 47 forks source link

[5.9] Optimize search for start-anchored regexes #684

Closed natecook1000 closed 1 year ago

natecook1000 commented 1 year ago

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.)

natecook1000 commented 1 year ago

@swift-ci Please test

natecook1000 commented 1 year ago

@swift-ci Please test macOS platform

natecook1000 commented 1 year ago

@swift-ci Please test macOS platform

natecook1000 commented 1 year ago

@swift-ci Please test macOS platform

natecook1000 commented 1 year ago

@swift-ci Please test macOS platform

natecook1000 commented 1 year ago

@swift-ci Please test macOS platform

natecook1000 commented 1 year ago

@swift-ci Please test macOS platform

natecook1000 commented 1 year ago

@swift-ci Please test macOS platform

natecook1000 commented 1 year ago

@swift-ci Please test