]> granicus.if.org Git - re2c/commitdiff
libre2c: restructured main loop to avoid double call to closure.
authorUlya Trofimovich <skvadrik@gmail.com>
Sat, 30 Mar 2019 09:59:50 +0000 (09:59 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Sat, 30 Mar 2019 09:59:50 +0000 (09:59 +0000)
lib/regexec_nfa_leftmost.cc
lib/regexec_nfa_leftmost_trie.cc
lib/regexec_nfa_posix.cc
lib/regexec_nfa_posix_backward.cc
lib/regexec_nfa_posix_kuklewicz.cc
lib/regexec_nfa_posix_trie.cc

index a7ba89d661a6edc92d4825a21058d0180417b1ce..8f894969e4de1a1080f101cd0be63e20437be490 100644 (file)
@@ -23,13 +23,12 @@ int regexec_nfa_leftmost(const regex_t *preg, const char *string
     // root state can be non-core, so we pass zero as origin to avoid checks
     const conf_t c0(ctx.nfa.root, 0, HROOT);
     ctx.reach.push_back(c0);
-    closure_leftmost_dfs(ctx);
 
     for (;;) {
+        closure_leftmost_dfs(ctx);
         const uint32_t sym = static_cast<uint8_t>(*ctx.cursor++);
         if (ctx.state.empty() || sym == 0) break;
         reach_on_symbol(ctx, sym);
-        closure_leftmost_dfs(ctx);
     }
 
     for (cconfiter_t i = ctx.state.begin(), e = ctx.state.end(); i != e; ++i) {
index 52aac9bb2f5380d0c344314c2bca8a3b319db50f..ba24d807af1b5d6af6006f15985772faddb6618c 100644 (file)
@@ -22,12 +22,11 @@ int regexec_nfa_leftmost_trie(const regex_t *preg, const char *string
 
     const conf_t c0(ctx.nfa.root, 0/* unused */, HROOT);
     ctx.reach.push_back(c0);
-    closure_leftmost_dfs(ctx);
     for (;;) {
+        closure_leftmost_dfs(ctx);
         const uint32_t sym = static_cast<uint8_t>(*ctx.cursor++);
         if (ctx.state.empty() || sym == 0) break;
         make_step(ctx, sym);
-        closure_leftmost_dfs(ctx);
     }
     make_final_step(ctx);
 
index 4d29d8a165f7b90ec1131b85d5a75407b9389fb3..b592075726177d9563d526782e07dd5be75eb697 100644 (file)
@@ -32,12 +32,11 @@ int regexec_nfa_posix(const regex_t *preg, const char *string
     // root state can be non-core, so we pass zero as origin to avoid checks
     const conf_t c0(ctx.nfa.root, 0, HROOT);
     ctx.reach.push_back(c0);
-    closure_posix(ctx);
     for (;;) {
+        closure_posix(ctx);
         const uint32_t sym = static_cast<uint8_t>(*ctx.cursor++);
         if (ctx.state.empty() || sym == 0) break;
         make_one_step(ctx, sym);
-        closure_posix(ctx);
     }
     make_final_step(ctx);
 
index c6bf48baa1fdb14f5ab3350dd8f83138bd246c4f..ac81c7fa589208db73be8d12a11831ed77f57569 100644 (file)
@@ -110,12 +110,11 @@ int regexec_nfa_posix_backward(const regex_t *preg, const char *string
     // 1st pass, forward: find longest match on a simple NFA
 
     ctx.reach.push_back(conf_t(ctx.nfa0->root, 0, 0));
-    closure_simple(ctx);
     for (;;) {
+        closure_simple(ctx);
         const uint32_t sym = static_cast<uint8_t>(*ctx.cursor++);
         if (ctx.state.empty() || sym == 0) break;
         make_one_step_simple(ctx, sym);
-        closure_simple(ctx);
     }
 
     for (cconfiter_t i = ctx.state.begin(), e = ctx.state.end(); i != e; ++i) {
@@ -147,13 +146,12 @@ int regexec_nfa_posix_backward(const regex_t *preg, const char *string
     std::fill(offsets5, offsets5 + sz, -2);
 
     ctx.reach.push_back(conf_t(ctx.nfa.root, 0, 0));
-    closure_posix(ctx);
     for (;;) {
+        closure_posix(ctx);
         if (ctx.state.empty() || ctx.cursor == string) break;
         const uint32_t sym = static_cast<uint8_t>(*--ctx.cursor);
         make_one_step(ctx, sym);
         --ctx.step;
-        closure_posix(ctx);
     }
     make_final_step(ctx);
 
index 5e82ea7fa051cee4d81374ac38d7f078292bc451..d508fe44be67df616196ad8614ef50f1241c5e11 100644 (file)
@@ -71,12 +71,11 @@ int regexec_nfa_posix_kuklewicz(const regex_t *preg, const char *string
     // root state can be non-core, so we pass zero as origin to avoid checks
     const conf_t c0(ctx.nfa.root, 0, HROOT);
     ctx.reach.push_back(c0);
-    closure_posix(ctx);
     for (;;) {
+        closure_posix(ctx);
         const uint32_t sym = static_cast<uint8_t>(*ctx.cursor++);
         if (ctx.state.empty() || sym == 0) break;
         make_one_step(ctx, sym);
-        closure_posix(ctx);
     }
     make_final_step(ctx);
 
index 76a045dc69afddcab183a238e2c04c0ebeda637f..378d615fdff13d893c9193cacdd94a16fb91c9a4 100644 (file)
@@ -23,12 +23,11 @@ int regexec_nfa_posix_trie(const regex_t *preg, const char *string
 
     const conf_t c0(ctx.nfa.root, 0, HROOT);
     ctx.reach.push_back(c0);
-    closure_posix_gtop(ctx);
     for (;;) {
+        closure_posix_gtop(ctx);
         const uint32_t sym = static_cast<uint8_t>(*ctx.cursor++);
         if (ctx.state.empty() || sym == 0) break;
         make_step(ctx, sym);
-        closure_posix_gtop(ctx);
     }
     make_final_step(ctx);