diff --git a/src/nfa/accel_dfa_build_strat.cpp b/src/nfa/accel_dfa_build_strat.cpp index 1f1b5e02..4508d4f1 100644 --- a/src/nfa/accel_dfa_build_strat.cpp +++ b/src/nfa/accel_dfa_build_strat.cpp @@ -41,6 +41,7 @@ #include "util/verify_types.h" #include +#include #include #include @@ -66,6 +67,17 @@ void dump_paths(const Container &paths) { DEBUG_PRINTF("%zu paths\n", paths.size()); } +static +vector reverse_alpha_remapping(const raw_dfa &rdfa) { + vector rv(rdfa.alpha_size - 1); /* TOP not required */ + + for (u32 i = 0; i < N_CHARS; i++) { + rv.at(rdfa.alpha_remap[i]).set(i); + } + + return rv; +} + static bool is_useful_path(const vector &good, const path &p) { for (const auto &g : good) { @@ -99,9 +111,10 @@ path append(const path &orig, const CharReach &cr, u32 new_dest) { } static -void extend(const raw_dfa &rdfa, const path &p, - map> &all, vector &out) { - dstate s = rdfa.states[p.dest]; +void extend(const raw_dfa &rdfa, const vector &rev_map, + const path &p, unordered_map> &all, + vector &out) { + const dstate &s = rdfa.states[p.dest]; if (!p.reach.empty() && p.reach.back().none()) { out.push_back(p); @@ -126,9 +139,9 @@ void extend(const raw_dfa &rdfa, const path &p, } flat_map dest; - for (unsigned i = 0; i < N_CHARS; i++) { - u32 succ = s.next[rdfa.alpha_remap[i]]; - dest[succ].set(i); + for (u32 i = 0; i < rev_map.size(); i++) { + u32 succ = s.next[i]; + dest[succ] |= rev_map[i]; } for (const auto &e : dest) { @@ -149,13 +162,14 @@ void extend(const raw_dfa &rdfa, const path &p, static vector> generate_paths(const raw_dfa &rdfa, dstate_id_t base, u32 len) { + const vector rev_map = reverse_alpha_remapping(rdfa); vector paths{path(base)}; - map> all; + unordered_map> all; all[base].push_back(path(base)); for (u32 i = 0; i < len && paths.size() < PATHS_LIMIT; i++) { vector next_gen; for (const auto &p : paths) { - extend(rdfa, p, all, next_gen); + extend(rdfa, rev_map, p, all, next_gen); } paths = move(next_gen); @@ -196,17 +210,6 @@ bool better(const AccelScheme &a, const AccelScheme &b) { return a.cr.count() < b.cr.count(); } -static -vector reverse_alpha_remapping(const raw_dfa &rdfa) { - vector rv(rdfa.alpha_size - 1); /* TOP not required */ - - for (u32 i = 0; i < N_CHARS; i++) { - rv.at(rdfa.alpha_remap[i]).set(i); - } - - return rv; -} - static bool double_byte_ok(const AccelScheme &info) { return !info.double_byte.empty() &&