Skip to content

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

3 participants