core: Make TwoWaySearcher reset its prefix memory when shifting by byteset

Closes #16878.
Add many comments to TwoWaySearcher.