Skip to content

[swift/main] Add a string-specific search algorithm #747

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
merged 1 commit into from
Jul 10, 2024

Conversation

natecook1000
Copy link
Member

Cherry-pick of #715 for the swift/main branch.

* Add a string-specific search algorithm

This adds a Boyer-Moore substring search algorithm, and updates the
`firstRange(of:)` and `ranges(of:)` methods to use that when both
pieces of the search are strings/substrings.

* Substring search: iterative rather than recursive

For large strings, a recursive search can run out of stack space.
This eliminates the issue by looping within the `nextRange` function.

* Dispatch string splitting to new searcher

* Remove generic on SubstringSearcher

* Remove unnecessary inlining annotations

* Update string algorithms tests

* Verify string/substring dispatch in algorithms

* Add tests for string.replacing maxReplacements

* Add fallback to naive search for small patterns

* Improve some comments/formatting in the string search
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000
Copy link
Member Author

@swift-ci Please test

@stephentyrone stephentyrone merged commit 5c93227 into swift/main Jul 10, 2024
3 checks passed
@stephentyrone stephentyrone deleted the swiftmain_search-algorithm branch July 10, 2024 15:17
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.

None yet

2 participants