Subject: bug#17350: [PATCH] grep: speed up for a case to repeat failure in DFA after success in kwset

From: Paul Eggert <[email-masked]>
Date: Sat, 03 May 2014 15:40:05 -0700

Norihiro Tanaka wrote:
> Sorry, I have discovered a bug in your improvement, and fix it.

Thanks for reporting and fixing that!  I installed that.  Also, I tried 
to change the code a bit to make similar bugs less likely in the future, 
and installed the attached followup patch.
From 995f0c43a0198d62e779ec5113a58e22889367aa Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sat, 3 May 2014 15:37:17 -0700
Subject: [PATCH] grep: clarify EGexecute slightly

* src/dfasearch.c (EGexecute): Change if-then-else to !if-else-then.
---
 src/dfasearch.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/dfasearch.c b/src/dfasearch.c
index 6d27489..4b3c79a 100644
--- a/src/dfasearch.c
+++ b/src/dfasearch.c
@@ -257,9 +257,9 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
               end = ((exact_kwset_match || !dfafast
                       || MAX (16, match - beg) < (match - prev_beg) >> 2)
                      ? match
-                     : (buflim - prev_beg) >> 2 <= MAX (16, match - beg)
-                     ? buflim
-                     : prev_beg + 4 * MAX (16, match - beg));
+                     : MAX (16, match - beg) < (buflim - prev_beg) >> 2
+                     ? prev_beg + 4 * MAX (16, match - beg)
+                     : buflim);
               end = memchr (end, eol, buflim - end);
               end = end ? end + 1 : buflim;
 
-- 
1.9.0