Mercurial > hg > Members > masakoha > testcode
changeset 322:62f4628d2c0d
tSearch loop unwind
author | Nozomi |
---|---|
date | Thu, 26 May 2016 19:57:44 +0900 |
parents | a1b65d39b947 |
children | 672c1be4eec7 |
files | regexParser/CharClass.h regexParser/threadedSearch.cc |
diffstat | 2 files changed, 39 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- 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) ;
--- 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 (c<ccv->begin) { - 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 (c<ccv[0].begin) goto noMatch; + else if (c<=ccv[0].end) goto match; + if (c<ccv[1].begin) goto noMatch; + else if (c<=ccv[1].end) goto match; + if (c<ccv[2].begin) goto noMatch; + else if (c<=ccv[2].end) goto match; + if (c<ccv[3].begin) goto noMatch; + else if (c<=ccv[3].end) goto match; + if (c<ccv[4].begin) goto noMatch; + else if (c<=ccv[4].end) goto match; + ccv += 5; + } + match: + // 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 (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