freebsd-skq/lib/libc/regex
Daniel C. Sobral e6a886d8db Enhance the optimization provided by pre-matching. Fix style bugs with
previous commits.

At the time we search the pattern for the "must" string, we now compute
the longest offset from the beginning of the pattern at which the must
string might be found. If that offset is found to be infinite (through
use of "+" or "*"), we set it to -1 to disable the heuristics applied
later.

After we are done with pre-matching, we use that offset and the point in
the text at which the must string was found to compute the earliest
point at which the pattern might be found.

Special care should be taken here. The variable "start" is passed to the
automata-processing functions fast() and slow() to indicate the point in
the text at which they should start working from. The real beginning of
the text is passed in a struct match variable m, which is used to check
for anchors. That variable, though, is initialized with "start", so we
must not adjust "start" before "m" is properly initialized.

Simple tests showed a speed increase from 100% to 400%, but they were
biased in that regexec() was called for the whole file instead of line
by line, and parenthized subexpressions were not searched for.

This change adds a single integer to the size of the "guts" structure,
and does not change the ABI.

Further improvements possible:

Since the speed increase observed here is so huge, one intuitive
optimization would be to introduce a bias in the function that computes
the "must" string so as to prefer a smaller string with a finite offset
over a larger one with an infinite offset. Tests have shown this to be a
bad idea, though, as the cost of false pre-matches far outweights the
benefits of a must offset, even in biased situations.

A number of other improvements suggest themselves, though:

	* identify the cases where the pattern is identical to the must
	string, and avoid entering fast() and slow() in these cases.

	* compute the maximum offset from the must string to the end of
	the pattern, and use that to set the point at which fast() and
	slow() should give up trying to find a match, and return then
	return to pre-matching.

	* return all the way to pre-matching if a "match" was found and
	later invalidated by back reference processing. Since back
	references are evil and should be avoided anyway, this is of
	little use.
2000-07-02 10:58:07 +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
engine.c Enhance the optimization provided by pre-matching. Fix style bugs with 2000-07-02 10:58:07 +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 Enhance the optimization provided by pre-matching. Fix style bugs with 2000-07-02 10:58:07 +00:00
regerror.c remove <ctype.h> - not needed 1999-07-26 05:50:43 +00:00
regex2.h Enhance the optimization provided by pre-matching. Fix style bugs with 2000-07-02 10:58:07 +00:00
regex.3 Remove from the notes a bug that it's said to have been fixed. 2000-07-02 10:34:25 +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
utils.h
WHATSNEW