From 7f693ddf06280a0e638f97a1810d454c20c62716 Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Tue, 13 Oct 2015 09:42:57 +0900 Subject: [PATCH 1/2] grep: improvement of performance of grep -Fw grep -Fw examines whether previous character is not word character or not after matching from a head of buffer. It is extremely slow. Now, if grep found potential match, seeks previous newline, and examines from there. --- src/kwsearch.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/kwsearch.c b/src/kwsearch.c index 5a91eb6..045ef46 100644 --- a/src/kwsearch.c +++ b/src/kwsearch.c @@ -124,7 +124,11 @@ Fexecute (char const *buf, size_t size, size_t *match_size, if (match_words) for (try = beg; ; ) { - if (wordchar (mb_prev_wc (buf, try, buf + size))) + char const *bol; + bol = beg; + while (buf < bol && bol[-1] != eol) + --bol; + if (wordchar (mb_prev_wc (bol, try, buf + size))) break; if (wordchar (mb_next_wc (try + len, buf + size))) { -- 2.4.6