]> granicus.if.org Git - re2c/commitdiff
Small simplifications in GOR1 initialization phase.
authorUlya Trofimovich <skvadrik@gmail.com>
Thu, 3 Jan 2019 09:53:57 +0000 (09:53 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Thu, 3 Jan 2019 09:53:57 +0000 (09:53 +0000)
Instead of using two stacks to weed out low-precedence initial
configurations with duplicate target state, let them remain on the
bottom of topsort stack, which effectively makes them ignored.

re2c/src/dfa/closure_posix.cc

index 96843f547017e9f365fa0578bfecdff86d95cb0d..1d5b2cfe9517d23c685017eb8947e95bdeeaa66f 100644 (file)
@@ -64,21 +64,20 @@ void closure_posix_gor1(determ_context_t &ctx)
 
     done.clear();
 
-    // Initialization: topsort stack must contain configurations with
-    // unique target state, ordered from the highest POSIX precedence
-    // (on top) to the lowest precedence (at the bottom).
+    // initialization: topsort stack must contain configurations
+    // ordered by POSIX precedence (with highest precedence on top)
     std::sort(init.begin(), init.end(), cmp_gor1_t(ctx));
-    for (cclositer_t c = init.begin(); c != init.end(); ++c) {
+    for (rcclositer_t c = init.rbegin(); c != init.rend(); ++c) {
         q = c->state;
         if (q->clos == NOCLOS) {
             q->clos = static_cast<uint32_t>(done.size());
             done.push_back(*c);
-            linear.push(q);
         }
-    }
-    for (; !linear.empty(); ) {
-        topsort.push(linear.top());
-        linear.pop();
+        else {
+            // duplicate state, but higher precedence => overwrite
+            done[q->clos] = *c;
+        }
+        topsort.push(q);
     }
 
     for (; !topsort.empty(); ) {