Fix memmem to avoid O(n^2) worst-case complexity.
authorEric Blake <ebb9@byu.net>
Wed, 19 Dec 2007 23:09:03 +0000 (16:09 -0700)
committerEric Blake <ebb9@byu.net>
Thu, 20 Dec 2007 13:02:01 +0000 (06:02 -0700)
commitfc068cf4eb6814e848e4dc54e1c5cf4c30a79a6f
treea195a67b5ddd7d22b8c62277871cab7435cc7b54
parente323f261972032e4a1eeee6102c2327e97c808df
Fix memmem to avoid O(n^2) worst-case complexity.

* lib/memmem.c (knuth_morris_pratt): New function.
(memmem): Use it if first few naive iterations fail.
* m4/memmem.m4 (gl_FUNC_MEMMEM): Detect cygwin bug.
* modules/memcmp (License): Set to LGPLv2+, not LGPL.
* modules/memchr (License): Likewise.
* modules/memmem (Depends-on): Add memcmp, memchr, stdbool, and
malloca.
* tests/test-memmem.c: Rewrite, borrowing ideas from
test-mbsstr1.c; the old version wouldn't even compile!
* modules/memmem-tests: New file.
* lib/string.in.h (rpl_memmem): Add declaration.
* modules/string (Makefile.am): Substitute REPLACE_MEMMEM.
* m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Default for
REPLACE_MEMMEM.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/memmem.c
lib/string.in.h
m4/memmem.m4
m4/string_h.m4
modules/memchr
modules/memcmp
modules/memmem
modules/memmem-tests [new file with mode: 0644]
modules/string
tests/test-memmem.c