summaryrefslogtreecommitdiff
path: root/src/kwsearch.c
diff options
context:
space:
mode:
authorNorihiro Tanaka <noritnk@kcn.ne.jp>2015-10-13 09:42:57 +0900
committerPaul Eggert <eggert@cs.ucla.edu>2015-10-16 22:42:06 -0700
commit79d7918c889dea0d83c270cc1e8a9d8786b20102 (patch)
treec0d587d6865e81c2a90087f642587a0a9c699b0b /src/kwsearch.c
parent09eca14b3b7d676ce87a8a4b162265c347643d2a (diff)
downloadgrep-79d7918c889dea0d83c270cc1e8a9d8786b20102.tar.gz
grep: improve performance of grep -Fw
* src/kwsearch.c (Fexecute): grep -Fw examined whether the previous character is a word character after matching from the head of the buffer. It is extremely slow. Now, if grep found a potential match, it looks for the previous newline, and examines from there.
Diffstat (limited to 'src/kwsearch.c')
-rw-r--r--src/kwsearch.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/kwsearch.c b/src/kwsearch.c
index 5a91eb63..045ef462 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)))
{