freebsd-dev/lib/libc/regex
Daniel C. Sobral 6049d9f0eb Add Boyler-Moore algorithm to pre-matching test.
The BM algorithm works by scanning the pattern from right to left,
and jumping as many characters as viable based on the text's mismatched
character and the pattern's already matched suffix.

This typically enable us to test only a fraction of the text's characters,
but has a worse performance than the straight-forward method for small
patterns. Because of this, the BM algorithm will only be used if the
pattern size is at least 4 characters.

Notice that this pre-matching is done on the largest substring of the
regular expression that _must_ be present on the text for a succesful
match to be possible at all.

For instance, "(xyzzy|grues)" will yield a null "must" substring, and,
therefore, not benefit from the BM algorithm at all. Because of the
lack of intelligence of the algorithm that finds the "must" string,
things like "charjump|matchjump" will also yield a null string. To
optimize that, "(char|match)jump" should be used.

The setup time (at regcomp()) for the BM algorithm will most likely
outweight any benefits for one-time matches. Given the slow regex(3)
we have, this is unlikely to be even perceptible, though.

The size of a regex_t structure is increased by 2*sizeof(char*) +
256*sizeof(int) + strlen(must)*sizeof(int). This is all inside the
regex_t's "guts", which is allocated dynamically by regcomp(). If
allocation of either of the two tables fail, the other one is freed.
In this case, the straight-forward algorithm is used for pre-matching.

Tests exercising the code path affected have shown a speed increase of
50% for "must" strings of length four or five.

API and ABI remain unchanged by this commit.

The patch submitted on the PR was not used, as it was non-functional.

PR: 14342
2000-06-29 04:48:34 +00:00
..
cclass.h Use locale for character classes instead of hardcoded values 1996-08-11 11:42:03 +00:00
cname.h General -Wall warning cleanup, part I. 1996-07-12 18:57:58 +00:00
COPYRIGHT BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
engine.c Add Boyler-Moore algorithm to pre-matching test. 2000-06-29 04:48:34 +00:00
Makefile.inc $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
re_format.7 $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
regcomp.c Add Boyler-Moore algorithm to pre-matching test. 2000-06-29 04:48:34 +00:00
regerror.c remove <ctype.h> - not needed 1999-07-26 05:50:43 +00:00
regex2.h Add Boyler-Moore algorithm to pre-matching test. 2000-06-29 04:48:34 +00:00
regex.3 $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
regexec.c int -> long changes that reduce the diffs with the NetBSD version to 1998-05-14 21:45:18 +00:00
regfree.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
utils.h BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
WHATSNEW BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00