diff regexParser/threadedSearch.cc @ 277:7b4bcc7b5ae6

nextTState implemented
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Sat, 30 Jan 2016 20:44:37 +0900
parents 8879eb8c64a8
children 99d635926ef3
line wrap: on
line diff
--- a/regexParser/threadedSearch.cc	Sat Jan 30 19:08:01 2016 +0900
+++ b/regexParser/threadedSearch.cc	Sat Jan 30 20:44:37 2016 +0900
@@ -46,8 +46,10 @@
         tState->stateSkip = tg->stateSkip;
         tState->stateContinue = tg->stateNothing;
     }
-    if (ccvSize == 0) return tState;
-    else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize);
+    if (ccvSize == 0) {
+        tState->ccv = NULL;
+        return tState;
+    } else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize);
     ccw = createCharClassWalker(state->cc);
     int i = 0;
     while (hasNext(ccw)) {
@@ -65,6 +67,21 @@
     return tState;
 }
 
+TStatePtr nextTState(BitVector bi,TransitionGeneratorPtr tg) {
+    // create tSearch in next state.
+    StatePtr state = tg->stateArray[bi.bitContainer];
+    if (state == NULL) {
+        // on the fly subset construction.
+        state = createState(tg,bi);
+        determinize(state,tg);
+        tg->stateArray[bi.bitContainer] = state;
+    }
+    if (state->tState == NULL) {
+        generateTState(state,tg);
+    }
+    return state->tState;
+}
+
 void tSearch(TSValue tsv) {
     next: while (tsv.buff.buffptr < tsv.buff.buffend) {
         unsigned char c = *tsv.buff.buffptr++;
@@ -79,24 +96,12 @@
                     // match the word.
                     // if (not match) continue;
                 }
-                TStatePtr current = ccv->tState;
-                if (current == NULL) {
-                    // create tSearch in next state.
-                    StatePtr state = tsv.tg->stateArray[ccv->state.bitContainer];
-                    if (state == NULL) {
-                        // on the fly subset construction.
-                        state = createState(tsv.tg,state->bitState);
-                        determinize(state,tsv.tg);
-                        tsv.tg->stateArray[state->bitState.bitContainer] = state;
-                    }
-                    if (state->tState == NULL) {
-                        current = generateTState(state,tsv.tg);
-                        ccv->tState = current;
-                    } else {
-                        ccv->tState = state->tState;
-                    }
+                if (ccv->tState) {
+                    tsv.current = ccv->tState;
+                } else {
+                    tsv.current = nextTState(ccv->state,tsv.tg);
+                    ccv->tState = tsv.current;
                 }
-                tsv.current = ccv->tState;
                 // tsv = tsv.current->stateContinue(tsv);
                 goto next;
             }