summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kwsearch.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/kwsearch.c b/src/kwsearch.c
index 045ef462..2997ae1a 100644
--- a/src/kwsearch.c
+++ b/src/kwsearch.c
@@ -124,10 +124,8 @@ Fexecute (char const *buf, size_t size, size_t *match_size,
if (match_words)
for (try = beg; ; )
{
- char const *bol;
- bol = beg;
- while (buf < bol && bol[-1] != eol)
- --bol;
+ char const *bol = memrchr (buf, eol, beg - buf);
+ bol = bol ? bol + 1 : buf;
if (wordchar (mb_prev_wc (bol, try, buf + size)))
break;
if (wordchar (mb_next_wc (try + len, buf + size)))
@@ -153,12 +151,10 @@ Fexecute (char const *buf, size_t size, size_t *match_size,
return -1;
success:
- if ((end = memchr (beg + len, eol, (buf + size) - (beg + len))) != NULL)
- end++;
- else
- end = buf + size;
- while (buf < beg && beg[-1] != eol)
- --beg;
+ end = memchr (beg + len, eol, (buf + size) - (beg + len));
+ end = end ? end + 1 : buf + size;
+ beg = memrchr (buf, eol, beg - buf);
+ beg = beg ? beg + 1 : buf;
len = end - beg;
success_in_beg_and_len:;
size_t off = beg - buf;