aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/string
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2017-03-18 00:53:24 +0000
committerEd Maste <emaste@FreeBSD.org>2017-03-18 00:53:24 +0000
commit01dc206b226cccc287d6e1bfb2c1ff619728fc72 (patch)
tree75fc8a763bf5944376633d944068091c02464b12 /lib/libc/string
parent88521634e964e3da78a0ce54109cddb59bf3f099 (diff)
Notes
Diffstat (limited to 'lib/libc/string')
-rw-r--r--lib/libc/string/memmem.c8
-rw-r--r--lib/libc/string/strstr.c8
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/libc/string/memmem.c b/lib/libc/string/memmem.c
index d5f74c5bf72b8..15ad55913d2bf 100644
--- a/lib/libc/string/memmem.c
+++ b/lib/libc/string/memmem.c
@@ -58,6 +58,14 @@ static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned ch
#define BITOP(a,b,op) \
((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
+/*
+ * Two Way string search algorithm, with a bad shift table applied to the last
+ * byte of the window. A bit array marks which entries in the shift table are
+ * initialized to avoid fully initializing a 1kb/2kb table.
+ *
+ * Reference: CROCHEMORE M., PERRIN D., 1991, Two-way string-matching,
+ * Journal of the ACM 38(3):651-675
+ */
static char *twoway_memmem(const unsigned char *h, const unsigned char *z, const unsigned char *n, size_t l)
{
size_t i, ip, jp, k, p, ms, p0, mem, mem0;
diff --git a/lib/libc/string/strstr.c b/lib/libc/string/strstr.c
index 6b1ac658ec86e..8ed58b81a875b 100644
--- a/lib/libc/string/strstr.c
+++ b/lib/libc/string/strstr.c
@@ -55,6 +55,14 @@ static char *fourbyte_strstr(const unsigned char *h, const unsigned char *n)
#define BITOP(a,b,op) \
((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
+/*
+ * Two Way string search algorithm, with a bad shift table applied to the last
+ * byte of the window. A bit array marks which entries in the shift table are
+ * initialized to avoid fully initializing a 1kb/2kb table.
+ *
+ * Reference: CROCHEMORE M., PERRIN D., 1991, Two-way string-matching,
+ * Journal of the ACM 38(3):651-675
+ */
static char *twoway_strstr(const unsigned char *h, const unsigned char *n)
{
const unsigned char *z;