3 ms·
One reason why someone might choose to do that is performance: it ensures that any precomputation required by the two-way algorithm is cached and only done once
by dbaupp 8y ago
One reason why someone might choose to do that is performance: it ensures that any precomputation required by the two-way algorithm is cached and only done once. After the first search, later ones can jump straight into the main search loop, rather than having to redo any set-up for the fixed needle "\r\n\r\n" (for two-way searcher, it's O(size of needle)).
If that setup-performance doesn't matter one can use https://crates.io/crates/twoway https://crates.io/crates/twoway to write:
twoway::find_bytes(&buffer[to_scan..], b"\r\n\r\n")
at the place where the search happens and skip all the caching effort.