<<< Date Index >>>     <<< Thread Index >>>

[PATCH] optimize pattern searching some



Cleaning up some entries from the RH bugzilla:
Original patch is from Tim Waugh (<twaugh@xxxxxxxxxx>) for
1.4.x, it applies to 1.5.6.

...
Here is a patch to make message searches slightly quicker by eliminating a
redundant strlen for each line in a message being checked against a pattern.

It makes mutt use getline, a GNU libc extension function, rather than 
fgets+strlen.

...

Bill
--- mutt-1.4.1/pattern.c.fast   2003-07-14 11:41:13.000000000 +0100
+++ mutt-1.4.1/pattern.c        2003-07-14 11:41:14.000000000 +0100
@@ -218,14 +218,15 @@
     /* search the file "fp" */
     while (lng > 0)
     {
-      if (fgets (buf, blen - 1, fp) == NULL)
+      ssize_t got = getline (&buf, &blen, fp);
+      if (got < 1)
        break; /* don't loop forever */
       if (regexec (rx, buf, 0, NULL, 0) == 0)
       {
        match = 1;
        break;
       }
-      lng -= mutt_strlen (buf);
+      lng -= got;
     }
     
     mx_close_message (&msg);