Jim Meyering wrote:
Paul, what do you think about making your heuristic apply only for non-pipes?
I'm a bit dubious, as grep exits early for other reasons, and did so before the
patch in question. For example, here:
seq 10000000000 | grep -q .
This is as of grep 2.19 (2014), due to a bug report where grep performed badly
by not exiting early <https://bugs.gnu.org/17427>. Which suggests that we'll get
bug reports in this area no matter what grep does....
Looking at other implementations, Solaris 11 grep is similar with -q. And
FreeBSD-current grep exits early for this case:
seq 10000000000 | grep -f /dev/null
Come to think of it, perhaps GNU grep should do a similar optimization for -f
/dev/null, if only to keep up with FreeBSD.
All the above being said, I am sympathetic to the bug report. Perhaps we can
eliminate the optimization if there are no file arguments and only options in
the set -EFivx are specified. Something like that anyway. The idea is to catch
common cases in old (and really, broken) scripts, without hurting performance in
general.