]> granicus.if.org Git - re2c/commitdiff
libre2c: use core state indices when possible.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 19 Feb 2019 14:22:40 +0000 (14:22 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 19 Feb 2019 14:22:40 +0000 (14:22 +0000)
re2c/lib/regex_impl.h
re2c/lib/regexec_nfa_leftmost.cc
re2c/lib/regexec_nfa_leftmost_trie.cc
re2c/lib/regexec_nfa_posix.cc
re2c/lib/regexec_nfa_posix_trie.cc

index 44662fe9262c91374b37cac4ac16caf66088cdae..ecb9f1e1b1f1c929af7a46afeda000afd5fd50aa 100644 (file)
@@ -115,7 +115,6 @@ struct simctx_t
 
 void init(simctx_t &ctx, const char *string);
 int finalize(const simctx_t &ctx, const char *string, size_t nmatch, regmatch_t pmatch[]);
-inline uint32_t index(const nfa_t *, const nfa_state_t *);
 int regexec_dfa(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
 int regexec_nfa_posix(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
 int regexec_nfa_posix_trie(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
@@ -129,11 +128,6 @@ int32_t history_t::push(int32_t idx, uint32_t step, tag_info_t info, uint32_t or
     return static_cast<int32_t>(nodes.size() - 1);
 }
 
-uint32_t index(const nfa_t *nfa, const nfa_state_t *state)
-{
-    return static_cast<uint32_t>(state - nfa->states);
-}
-
 bool ran_or_fin_t::operator()(const conf_t &c)
 {
     switch (c.state->type) {
index ed98131b855f31ae58668f005c50f835f8c33c47..b1c8d6d942e2ac39096e21343b76e6637f5eca6e 100644 (file)
@@ -20,6 +20,7 @@ int regexec_nfa_leftmost(const regex_t *preg, const char *string
     simctx_t &ctx = *preg->simctx;
     init(ctx, string);
 
+    // root state can be non-core, so we pass zero as origin to avoid checks
     const conf_t c0(ctx.nfa->root, 0, history_t::ROOT);
     ctx.reach.push_back(c0);
     closure_leftmost(ctx);
index cadc47689900811fd1bbda5af62b6b33f198c503..7329fbd1bece0a7dbf22a05cda0c44189a3e1eae 100644 (file)
@@ -19,7 +19,8 @@ int regexec_nfa_leftmost_trie(const regex_t *preg, const char *string
     simctx_t &ctx = *preg->simctx;
     init(ctx, string);
 
-    const conf_t c0(ctx.nfa->root, 0, history_t::ROOT);
+    nfa_state_t *s0 = ctx.nfa->root;
+    const conf_t c0(s0, s0->coreid, history_t::ROOT);
     ctx.reach.push_back(c0);
     closure_leftmost(ctx);
 
index 9a246b91bdc3937336484fcf36f9df61506ae91a..da241885c177e6a30d5cc24fb69d28a67fab7eac 100644 (file)
@@ -51,6 +51,7 @@ int do_regexec(const regex_t *preg, const char *string
     simctx_t &ctx = *preg->simctx;
     init(ctx, string);
 
+    // root state can be non-core, so we pass zero as origin to avoid checks
     const conf_t c0(ctx.nfa->root, 0, history_t::ROOT);
     ctx.reach.push_back(c0);
     closure_posix<ALG>(ctx);
index 1e55edd2e9fcdd9f11be00939fb3332c1f6ab47c..7f6e66248290a1cbb8d2c30aa3d3f8d16c9794f2 100644 (file)
@@ -57,9 +57,8 @@ int regexec_nfa_posix_trie(const regex_t *preg, const char *string
     simctx_t &ctx = *preg->simctx;
     init(ctx, string);
 
-    const nfa_t *nfa = ctx.nfa;
-
-    const conf_t c0(nfa->root, index(nfa, nfa->root), history_t::ROOT);
+    nfa_state_t *s0 = ctx.nfa->root;
+    const conf_t c0(s0, s0->coreid, history_t::ROOT);
     ctx.reach.push_back(c0);
     closure_posix(ctx);
     for (;;) {
@@ -75,7 +74,6 @@ int regexec_nfa_posix_trie(const regex_t *preg, const char *string
 
 void make_step(simctx_t &ctx, uint32_t sym)
 {
-    const nfa_t *nfa = ctx.nfa;
     const confset_t &state = ctx.state;
     confset_t &reach = ctx.reach;
     cconfiter_t b = state.begin(), e = state.end(), i;
@@ -90,7 +88,7 @@ void make_step(simctx_t &ctx, uint32_t sym)
         if (s->type == nfa_state_t::RAN) {
             for (const Range *r = s->ran.ran; r; r = r->next()) {
                 if (r->lower() <= sym && sym < r->upper()) {
-                    const conf_t c(s->ran.out, index(nfa, s), i->thist);
+                    const conf_t c(s->ran.out, s->coreid, i->thist);
                     reach.push_back(c);
                     break;
                 }