Closed yyzdtccjdtc closed 2 years ago
Thanks for the info!
I'm already aware of Boyer-Moore, but intentionally used naive string search instead to keep things simple. The example isn't meant to demonstrate search algorithms, but rather is meant to demonstrate how you would integrate any search algorithm (be it Boyer-Moore, a regex engine, or whatever) into an efficient search-and-replace function for Ropey.
https://github.com/cessen/ropey/blob/d9c841b2ef4ae7ea97c13a99fc26b36ae14ebe12/examples/search_and_replace.rs#L156
For the next function here, by change the linear search to the Boyer-Moore string search algorithm and then it can skip some unnecessary char comparison, then reduce the memory operations and improve the performance.
According to my test it will get a 96.5% speedup (12.2s to 6.22s).
Here's the modified code:
Hope this information helps!