From b8f24ddeb7ddf211a4dce662734ef4387d48b4c2 Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Sun, 30 Mar 2014 21:03:58 +0900 Subject: [PATCH] grep: speed-up for line matching in fgrep If fails in line matching at a position found by kwsexec(), the line never matches in line matching. So the line is skipped. * src/kwsearch.c (Fexecute): speed-up for line matching. --- src/kwsearch.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/kwsearch.c b/src/kwsearch.c index dd01518..037b78c 100644 --- a/src/kwsearch.c +++ b/src/kwsearch.c @@ -141,11 +141,9 @@ Fexecute (char const *buf, size_t size, size_t *match_size, goto success_in_beg_and_len; if (match_lines) { - if (beg > buf && beg[-1] != eol) - continue; - if (beg + len < buf + size && beg[len] != eol) - continue; - goto success; + if (beg[-1] == eol && beg[len] == eol) + goto success; + beg = memchr (beg, eol, buf + size - beg); } else if (match_words) for (try = beg; ; ) -- 1.9.1