Subject: bug#22239: bug#21763: bug#22239: bug#22357: grep -f not only huge memory usage, but also huge time cost

From: Paul Eggert <[email-masked]>
Date: Mon, 26 Dec 2016 12:07:49 -0800

Norihiro Tanaka wrote:
> Hmm, how about the following test cases, although it is extreame?

I don't think we need to worry about performance for the case when -w is given, 
and a pattern matches data that contains non-word characters. In practice, such 
cases are rare. I expect that most users would be surprised that -w can match 
non-word characters, and that users wouldn't object to -w rejecting such matches 
(if this wouldn't hurt performance significantly).

While looking into this I did find a very small performance tweak for the test 
case, and installed the attached.
From 7ad36793e6bc43b98a37b1512b057a7a03ed10b2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Mon, 26 Dec 2016 09:42:29 -0800
Subject: [PATCH] grep: minor performance tweak for pure functions

* src/search.h (wordchars_size, wordchar_next, wordchar_prev):
Declare to be pure.
---
 src/search.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/search.h b/src/search.h
index 469fc9c..1aa2f94 100644
--- a/src/search.h
+++ b/src/search.h
@@ -48,9 +48,10 @@ typedef signed char mb_len_map_t;
 /* searchutils.c */
 extern void wordinit (void);
 extern kwset_t kwsinit (bool);
-extern size_t wordchars_size (char const *, char const *);
-extern size_t wordchar_next (char const *, char const *);
-extern size_t wordchar_prev (char const *, char const *, char const *);
+extern size_t wordchars_size (char const *, char const *) _GL_ATTRIBUTE_PURE;
+extern size_t wordchar_next (char const *, char const *) _GL_ATTRIBUTE_PURE;
+extern size_t wordchar_prev (char const *, char const *, char const *)
+  _GL_ATTRIBUTE_PURE;
 extern ptrdiff_t mb_goback (char const **, char const *, char const *);
 
 /* dfasearch.c */
-- 
2.7.4