In dfaexec(), if reaches at eolbyte, we can skip checking of multibyte
character boundary.  So then process mbp until here.

Norihiro
From e23f55d85eaf08a7e18f84f13f6c69fa239c9dc6 Mon Sep 17 00:00:00 2001
From: Norihiro Tanaka <[email protected]>
Date: Mon, 14 Apr 2014 09:08:09 +0900
Subject: [PATCH] grep: skip checking of multibyte character boundary, reaching
 at eolbyte

* src/dfa.c (dfaexec): Skip checking of multibyte character boundary,
reaching at eolbyte.
---
 src/dfa.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/dfa.c b/src/dfa.c
index c93f451..98ed8e7 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -3352,10 +3352,6 @@ dfaexec (struct dfa *d, char const *begin, char *end,
           continue;
         }
 
-      /* If the previous character was a newline, count it.  */
-      if ((char *) p <= end && p[-1] == eol && count)
-        ++*count;
-
       /* Check if we've run off the end of the buffer.  */
       if ((char *) p > end)
         {
@@ -3363,6 +3359,16 @@ dfaexec (struct dfa *d, char const *begin, char *end,
           return NULL;
         }
 
+      /* If the previous character was a newline, count it, and skip
+         checking of multibyte character boundary until here.  */
+      if (p[-1] == eol)
+        {
+          if (count)
+            ++*count;
+          if (d->mb_cur_max > 1)
+            mbp = p;
+        }
+
       if (s >= 0)
         {
           if (!d->trans[s])
-- 
1.9.2

Reply via email to