From 0202a83b3d0de224a5d606958e3719244d546548 Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Sun, 17 Nov 2019 07:20:41 +0900 Subject: [PATCH 1/2] grep: fix performance degration with previous patch * src/kwsearch.c (Fexecute): Avoid unnecessary backwards in non-UTF8 multibyte locales. --- src/kwsearch.c | 15 ++++++++++++--- 1 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/kwsearch.c b/src/kwsearch.c index 5edff79..f590d19 100644 --- a/src/kwsearch.c +++ b/src/kwsearch.c @@ -224,9 +224,18 @@ Fexecute (void *vcp, char const *buf, size_t size, size_t *match_size, goto success; /* We need a preceding mb_start pointer. Use the beginning of line - if there is a preceding newline, else BUF. */ - char const *nl = memrchr (mb_start, eol, beg - mb_start); - mb_start = nl ? nl + 1 : buf; + if there is a preceding newline. */ + if (mb_check) + { + char const *nl = memrchr (buf, eol, beg - buf); + mb_start = nl ? nl + 1 : buf; + } + else + { + char const *nl = memrchr (mb_start, eol, beg - mb_start); + if (nl) + mb_start = nl + 1; + } /* Succeed if neither the preceding nor the following character is a word constituent. If the preceding is not, yet the following -- 1.7.1