diff -ru /usr/src/lib/libc/regex/engine.c re/engine.c --- /usr/src/lib/libc/regex/engine.c Mon Jul 31 01:30:37 2000 +++ engine.c Wed Jan 29 17:48:31 2003 @@ -154,6 +154,8 @@ register const sopno gl = g->laststate; char *start; char *stop; + char *earlyStop; + int mlen; /* Boyer-Moore algorithms variables */ register char *pp; int cj, mj; @@ -176,17 +178,18 @@ return(REG_INVARG); /* prescreening; this does wonders for this rather slow code */ - if (g->must != NULL) { + mustfirst = g->must; + if (mustfirst != NULL) { if (g->charjump != NULL && g->matchjump != NULL) { - mustfirst = g->must; - mustlast = g->must + g->mlen - 1; + mlen = g->mlen - 1; + mustlast = g->must + mlen; charjump = g->charjump; matchjump = g->matchjump; pp = mustlast; - for (dp = start+g->mlen-1; dp < stop;) { + for (dp = start+mlen; dp < stop;) { /* Fast skip non-matches */ - while (dp < stop && charjump[*dp]) - dp += charjump[*dp]; + while (dp < stop && (cj = charjump[*dp])) + dp += cj; if (dp >= stop) break; @@ -209,12 +212,13 @@ if (pp != mustfirst) return(REG_NOMATCH); } else { - for (dp = start; dp < stop; dp++) - if (*dp == g->must[0] && - stop - dp >= g->mlen && - memcmp(dp, g->must, (size_t)g->mlen) == 0) + mlen = g->mlen; + earlyStop = stop - mlen + 1; + for (dp = start; dp < earlyStop; dp++) + if (*dp == mustfirst[0] && + memcmp(dp, mustfirst, (size_t)mlen) == 0) break; - if (dp == stop) /* we didn't find g->must */ + if (dp == earlyStop) /* we didn't find g->must */ return(REG_NOMATCH); } }