From: Ulya Trofimovich Date: Sat, 30 Mar 2019 09:59:50 +0000 (+0000) Subject: libre2c: restructured main loop to avoid double call to closure. X-Git-Tag: 1.2~85 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d7946a18f2291dc5fc8a424aa227d2915f60307;p=re2c libre2c: restructured main loop to avoid double call to closure. --- diff --git a/lib/regexec_nfa_leftmost.cc b/lib/regexec_nfa_leftmost.cc index a7ba89d6..8f894969 100644 --- a/lib/regexec_nfa_leftmost.cc +++ b/lib/regexec_nfa_leftmost.cc @@ -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(*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) { diff --git a/lib/regexec_nfa_leftmost_trie.cc b/lib/regexec_nfa_leftmost_trie.cc index 52aac9bb..ba24d807 100644 --- a/lib/regexec_nfa_leftmost_trie.cc +++ b/lib/regexec_nfa_leftmost_trie.cc @@ -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(*ctx.cursor++); if (ctx.state.empty() || sym == 0) break; make_step(ctx, sym); - closure_leftmost_dfs(ctx); } make_final_step(ctx); diff --git a/lib/regexec_nfa_posix.cc b/lib/regexec_nfa_posix.cc index 4d29d8a1..b5920757 100644 --- a/lib/regexec_nfa_posix.cc +++ b/lib/regexec_nfa_posix.cc @@ -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(*ctx.cursor++); if (ctx.state.empty() || sym == 0) break; make_one_step(ctx, sym); - closure_posix(ctx); } make_final_step(ctx); diff --git a/lib/regexec_nfa_posix_backward.cc b/lib/regexec_nfa_posix_backward.cc index c6bf48ba..ac81c7fa 100644 --- a/lib/regexec_nfa_posix_backward.cc +++ b/lib/regexec_nfa_posix_backward.cc @@ -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(*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(*--ctx.cursor); make_one_step(ctx, sym); --ctx.step; - closure_posix(ctx); } make_final_step(ctx); diff --git a/lib/regexec_nfa_posix_kuklewicz.cc b/lib/regexec_nfa_posix_kuklewicz.cc index 5e82ea7f..d508fe44 100644 --- a/lib/regexec_nfa_posix_kuklewicz.cc +++ b/lib/regexec_nfa_posix_kuklewicz.cc @@ -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(*ctx.cursor++); if (ctx.state.empty() || sym == 0) break; make_one_step(ctx, sym); - closure_posix(ctx); } make_final_step(ctx); diff --git a/lib/regexec_nfa_posix_trie.cc b/lib/regexec_nfa_posix_trie.cc index 76a045dc..378d615f 100644 --- a/lib/regexec_nfa_posix_trie.cc +++ b/lib/regexec_nfa_posix_trie.cc @@ -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(*ctx.cursor++); if (ctx.state.empty() || sym == 0) break; make_step(ctx, sym); - closure_posix_gtop(ctx); } make_final_step(ctx);