Somewhat confusing since it has to look at every byte to find the newlines. They are using a pretty specific definition of "look".
Somewhat confusing since it has to look at every byte to find the newlines. They are using a pretty specific definition of "look".
> Moreover, GNU grep AVOIDS BREAKING THE INPUT INTO LINES. Looking for newlines would slow grep down by a factor of several times, because to find the newlines it would have to look at every byte!
I assume the Boyer Moore preprocessor reads a lot of bytes also.
Not disputing it's more efficient, but there's no magic. It avoids reading some bytes when and if it can.
It can whenever you don't ask for line numbers, can't it?
> It probably looks for newlines after a match is found
Probably, yeah. Counting number of newlines in a range, without caring just where they fall, can probably be pretty darned fast with vector instructions. Idk if that's worth the additional pass, though.
Another way of looking at is just considering the ^ another character (plus one-off special handling for start of file).