bug#51231: increase performance and usability of binary search with -P
An all-ASCII pattern can match non-ASCII data. For example, the pattern 'a.b' can match the string 'aΓb'. So it's not clear to me that the patch is correct in general. For speed, try setting LC_ALL='C'.
bug#51231: increase performance and usability of binary search with -P
The following patch increase performance of grep when looking at binary data, without any side effects: Summary 'cd grep; ./src/grep -Pc foo /Users/carlo/Downloads/FreeBSD-13.0-BETA2-amd64.vhd' ran 1.77 ± 0.02 times faster than 'cd grep.base; ./src/grep -Pc foo /Users/carlo/Downloads/FreeBSD