On Sat, Jan 9, 2021 at 12:14 PM Eli Zaretskii wrote: > Yes, probably. > > But before we do any changes here, we need a test suite. Would you > mind adding the necessary tests to test/src/xdisp-tests.el? Okay, I added a few basic tests for this case. I don't know if that's the best way to test it, but it's what I could figure out. The implementation bypasses the extra backtrack for the FROM, but the algorithm for the TO is the same as I first submitted. In that case, it's not really an extra backtrack since I have to dec to read the byte. If I had access to dec_bytepos declared in syntax.c, I think I could use that to avoid the extra backtrack (I'd fetch the dec_bytepos (bpos)) and test that and then only move the pointers if not breaking from the loop. I left the fetch_char_advance in the TO algorithm since it didn't seem necessary to replace it with separate fetch/inc_both. This could be done w/o the backtracking entirely by keeping two pointers, but that's more complicated, probably not much more efficient (if at all) and this will likely never be called in a tight loop. Let me know how this looks and if you want me to make any tweaks.