Hi,

CVS grep is slower than it needs to be if the leading context is
ridiculously large and matches are found.  For instance, try:

    grep -B 1000000000 / /etc/shells

The problem seems to be that the first loop in prtext() is almost
useless when out_before is much higher than the buffered context.
It can be fixed by moving the interior test out a level:

Index: src/grep.c
===================================================================
RCS file: /sources/grep/grep/src/grep.c,v
retrieving revision 1.125
diff -u -r1.125 grep.c
--- src/grep.c  10 Oct 2007 04:29:47 -0000      1.125
+++ src/grep.c  7 Jan 2008 17:25:41 -0000
@@ -974,11 +974,10 @@
       /* Deal with leading context crap. */
 
       bp = lastout ? lastout : bufbeg;
-      for (i = 0; i < out_before; ++i)
-       if (p > bp)
-         do
-           --p;
-         while (p[-1] != eol);
+      for (i = 0; i < out_before && p > bp; ++i)
+       do
+         --p;
+       while (p[-1] != eol);
 
       /* We print the SEP_STR_GROUP separator only if our output is
         discontiguous from the last output in the file. */

Cheers,
Gary.
-- 
     Gary Wong           [EMAIL PROTECTED]           
http://cs-people.bu.edu/gtw/

Attachment: pgpBleQge2A68.pgp
Description: PGP signature

Reply via email to