memchr() of glibc is faster than seeking by delta1 on some platforms.
So, when there is no chance to match for a while, use it on them.

Speed-up about 3x in best case, 10% in normal case by this patch.

It's still available only for x86 and x86-64 platform.

Norihiro
From 90ac2597511dd8ed44eee618df39c1ef947ea129 Mon Sep 17 00:00:00 2001
From: Norihiro Tanaka <[email protected]>
Date: Thu, 3 Apr 2014 22:57:09 +0900
Subject: [PATCH 2/2] grep: speed-up by using memchr() in Boyer-Moore searching

memchr() of glibc is faster than seeking by delta1 on some platforms.
When there is no chance to match for a while, use it on them.
* src/kwset.c (bmexec): Use memchr() in Boyer-Moore searching.
---
 src/kwset.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/kwset.c b/src/kwset.c
index 8d8aa07..c95bc56 100644
--- a/src/kwset.c
+++ b/src/kwset.c
@@ -531,8 +531,27 @@ bmexec (kwset_t kwset, char const *text, size_t size)
             d = d1[U(tp[-1])], tp += d;
             if (d == 0)
               goto found;
-            d = d1[U(tp[-1])], tp += d;
-            d = d1[U(tp[-1])], tp += d;
+            /* memchar() of glibc is faster than seeking by delta1 on
+               some platforms.  When there is no chance to match for a
+               while, use it on them.  */
+#if defined(__GLIBC__) && (defined(__i386__) || defined(__x86_64__))
+            if (!trans)
+              {
+                tp = memchr (tp - 1, gc1, size + text - tp + 1);
+                if (tp)
+                  {
+                    ++tp;
+                    goto found;
+                  }
+                else
+                  return -1;
+              }
+            else
+#endif
+              {
+                d = d1[U(tp[-1])], tp += d;
+                d = d1[U(tp[-1])], tp += d;
+              }
           }
         break;
       found:
-- 
1.9.1

Reply via email to