# HG changeset patch # User Nozomi # Date 1464260264 -32400 # Node ID 62f4628d2c0d724d0bc141e7f358dec69ad388af # Parent a1b65d39b947bad4699653d984ec2c583e66dfd8 tSearch loop unwind diff -r a1b65d39b947 -r 62f4628d2c0d regexParser/CharClass.h --- a/regexParser/CharClass.h Mon May 16 17:03:17 2016 +0900 +++ b/regexParser/CharClass.h Thu May 26 19:57:44 2016 +0900 @@ -1,4 +1,5 @@ #include "regexParser.h" +#define MAXCHAR (256) extern CharClassPtr createCharClassWord(RegexInfoPtr ri) ; extern CharClassPtr insertCharClass(CharClassPtr cc, unsigned long begin, unsigned long end) ; diff -r a1b65d39b947 -r 62f4628d2c0d regexParser/threadedSearch.cc --- a/regexParser/threadedSearch.cc Mon May 16 17:03:17 2016 +0900 +++ b/regexParser/threadedSearch.cc Thu May 26 19:57:44 2016 +0900 @@ -84,7 +84,7 @@ tState->ccv = NULL; state->tState = tState; return tState; - } else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize); + } else tState->ccv = (ccv*)malloc(sizeof(ccv)*(ccvSize+1)); ccw = createCharClassWalker(state->cc); int i = 0; while (hasNext(ccw)) { @@ -98,6 +98,10 @@ ccv->state = cc->nextState; ccv->w = cc->cond.w; } + struct ccv *ccv = &tState->ccv[i]; + ccv->begin = MAXCHAR+1; + ccv->end = ccv->begin; + ccv->tState = NULL; free(ccw); state->tState = tState; return tState; @@ -121,9 +125,6 @@ #define DEBUG 0 TSValue tSearch(TSValue tsv) { -#if DEBUG - TSValuePtr tsvp = &tsv; // make tsv visible in lldb -#endif next: while (tsv.buff.buffptr < tsv.buff.buffend) { tsv = tsv.current->stateMatch(tsv); if (tsv.current->ccvSize==0) { @@ -132,41 +133,43 @@ } unsigned char c = *tsv.buff.buffptr++; // printState(tsv.current->state); - for (int i = 0; i < tsv.current->ccvSize; i++) { - CCVPtr ccv = &tsv.current->ccv[i]; - if (cbegin) { - tsv.current = tsv.tg->stateStart->tState; - tsv = tsv.current->stateSkip(tsv); - goto next; - } else if (c<=ccv->end) { - // range matched. - if (ccv->w.word) { - WordPtr w; - for (w = &ccv->w;w;w = w->next) { - // match the word. - if (strncmp((const char *)w->word,(const char *)tsv.buff.buffptr-1,w->length)==0) break; - } - if (!w) continue; // if (not match) continue; - tsv.buff.buffptr += w->length - 1; + CCVPtr ccv = &tsv.current->ccv[0]; + for (;;) { + if (cw.word) { + WordPtr w; + for (w = &ccv->w;w;w = w->next) { + // match the word. + if (strncmp((const char *)w->word,(const char *)tsv.buff.buffptr-1,w->length)==0) break; } - if (ccv->tState) { - tsv.current = ccv->tState; - } else { - tsv.current = nextTState(ccv->state,tsv.tg); - ccv->tState = tsv.current; - } - goto next; + if (!w) continue; // if (not match) continue; + tsv.buff.buffptr += w->length - 1; } - } - tsv.current = tsv.tg->stateStart->tState; - tsv = tsv.current->stateSkip(tsv); + if (ccv->tState) { + tsv.current = ccv->tState; + } else { + tsv.current = nextTState(ccv->state,tsv.tg); + ccv->tState = tsv.current; + } + goto next; + noMatch: + tsv.current = tsv.tg->stateStart->tState; + tsv = tsv.current->stateSkip(tsv); } -#if DEBUG - *tsvp = tsv; - return *tsvp; -#else return tsv; -#endif } TSValue