From cb6a695c8507ee35bf2d2236445bc0941112e38a Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Tue, 13 Oct 2015 09:19:10 +0900 Subject: [PATCH 3/5] grep: use grep matcher for grep -Fw when unibyte In single byte locales with grep -Fw, prefer the grep matcher to the kwset matcher, as the former uses KWset and a DFA, whereas the latter calls kwsexec many times until it matches a word. * src/grep.c (main): Change pattern for fgrep into grep for grep -Fw in single byte locales. --- src/grep.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/grep.c b/src/grep.c index d8ea70f..0ca0d9a 100644 --- a/src/grep.c +++ b/src/grep.c @@ -2563,9 +2563,12 @@ 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))) + (2) the pattern matches words (where grep is typically faster), or + (3) 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))) + || (MB_CUR_MAX == 1 && match_words)) { size_t new_keycc; char *new_keys; -- 2.1.4