Basically every modern language has solved this...
https://lemire.me/blog/2020/09/03/sentinels-can-be-faster/?a...
Results:
N = 10000
range 1218.1
sentinel 937.258
mine 672.227
ratio 1.29964
(ratio is range/sentinel, not mine/whatever)You can get even more crazy with SIMD. But for all that you need to know the length beforehand.
Edit: The b4 variable should actually be called b8. That's a remnant of a previous version, where I used 32-bit chunks.
https://lemire.me/blog/2020/09/03/sentinels-can-be-faster/?a...
package main
import "fmt"
func main() {
fmt.Printf("%q\n", "hello \x00 world")
}