Skip to content

[6.0] Add a string-specific search algorithm #748

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 2 commits into from
Jul 15, 2024

Conversation

natecook1000
Copy link
Member

  • Explanation: Significant performance improvement for substring-searching methods like contains(_:) and firstRange(of:).
  • Original PR: Add a string-specific search algorithm #715
  • Risk: Low, only affects substring searching methods.
  • Reviewed by: @Catfish_Man
  • Resolves: rdar://129496154
  • Tests: Full swift-ci testing and full string-processing package testing

Cherry pick of #715 to the swift/release/6.0 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

@natecook1000
Copy link
Member Author

@swift-ci Please test Windows platform

@stephentyrone stephentyrone merged commit 420a8c2 into swift/release/6.0 Jul 15, 2024
3 checks passed
@stephentyrone stephentyrone deleted the swift6_search-algorithm branch July 15, 2024 17:36
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