Subject: bug#17420: closed (bug#17420: [PATCH] grep: always convert fgrep to grep)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 10 May 2014 23:40:03 +0000

Your bug report

#17420: [PATCH] grep: always convert fgrep to grep

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
17420: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17420
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: bug#17420: [PATCH] grep: always convert fgrep to grep
From: Norihiro Tanaka <[email-masked]>
To: Paul Eggert <[email-masked]>
Cc: [email-masked]
Date: Sun, 11 May 2014 08:39:09 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

> Is there a better heuristic for deciding whether to use Commentz-Walter?

No, I have no idea.

> Can the Galil rule be adapted to Commentz-Walter?

No, I don't know even whether we can do it.

> Another possibility might be to replace Commentz-Walter with some other algorithm (Aho-Corasick, modified Wu-Manber, etc.).

DFA is already like Aho-Corasick.  So even if we imprement them, there
will be no merit much in spite of big changes.

The argument has convinced me that we shouldn't apply the patch now.

Thanks,
Norihiro

Subject: [PATCH] grep: always convert fgrep to grep
From: Norihiro Tanaka <[email-masked]>
To: [email-masked]
Date: Tue, 06 May 2014 22:36:57 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

fgrep uses different matcher from grep, but there is no reason why it
must be so.  Further more, fgrep matcher is slower than grep matcher in
many cases, because it never uses DFA.  This patch converts fgrep to grep
any time.

By the way, if `FGREP_NO_DFA' env. is set, fgrep still uses fgrep matcher.
It may be required in some cases.  fgrep matcher requires less memory
than grep matcher even if a pattern is too long, and/or is faster than
it in some cases to have multiple patterns.
From a326b5fbfcb3ae547001dcc051272ae88cebcc7d Mon Sep 17 00:00:00 2001
From: Norihiro Tanaka <[email-masked]>
Date: Tue, 6 May 2014 16:00:34 +0900
Subject: [PATCH] grep: always convert fgrep to grep

src/grep.c (main): Do it.
---
 src/grep.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/grep.c b/src/grep.c
index a661fc0..35f4c75 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -2336,18 +2336,22 @@ main (int argc, char **argv)
   /* If fgrep in a multibyte locale, then use grep if either
      (1) case is ignored (where grep is typically faster), or
      (2) the pattern has an encoding error (where fgrep might not work).  */
-  if (compile == Fcompile && MB_CUR_MAX > 1
-      && (match_icase || contains_encoding_error (keys, keycc)))
+  if (compile == Fcompile)
     {
-      size_t new_keycc;
-      char *new_keys;
-      fgrep_to_grep_pattern (keycc, keys, &new_keycc, &new_keys);
-      free (keys);
-      keys = new_keys;
-      keycc = new_keycc;
-      matcher = "grep";
-      compile = Gcompile;
-      execute = EGexecute;
+      if (!getenv ("FGREP_NO_DFA"))
+        {
+          size_t new_keycc;
+          char *new_keys;
+          fgrep_to_grep_pattern (keycc, keys, &new_keycc, &new_keys);
+          free (keys);
+          keys = new_keys;
+          keycc = new_keycc;
+          matcher = "grep";
+          compile = Gcompile;
+          execute = EGexecute;
+        }
+      else if (contains_encoding_error (keys, keycc))
+        error (EXIT_TROUBLE, 0, _("contains encoding error"));
     }
 
   if (MB_CUR_MAX > 1)
-- 
1.9.2