dfa: allow smwr to avoid lengthy daddy recalc

This commit is contained in:
Justin Viiret
2017-04-11 12:44:20 +10:00
committed by Matthew Barr
parent 1538d90a9e
commit beac58fcb4
3 changed files with 26 additions and 15 deletions

View File

@@ -692,18 +692,20 @@ bool is_slow(const raw_dfa &rdfa, const set<dstate_id_t> &accel,
static
bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, const CompileContext &cc,
const ReportManager &rm, bool has_literals,
const ReportManager &rm, bool has_non_literals,
set<dstate_id_t> &accel_states) {
// If we determinised literals, then we only need to consider the init
// If we determinised only literals, then we only need to consider the init
// states for acceleration.
bool only_accel_init = has_literals;
bool only_accel_init = !has_non_literals;
bool trust_daddy_states = !has_non_literals;
bytecode_ptr<NFA> dfa = nullptr;
if (cc.grey.allowSmallWriteSheng) {
dfa = shengCompile(rdfa, cc, rm, only_accel_init, &accel_states);
}
if (!dfa) {
dfa = mcclellanCompile(rdfa, cc, rm, only_accel_init, &accel_states);
dfa = mcclellanCompile(rdfa, cc, rm, only_accel_init,
trust_daddy_states, &accel_states);
}
return dfa;
}
@@ -711,14 +713,14 @@ bytecode_ptr<NFA> getDfa(raw_dfa &rdfa, const CompileContext &cc,
static
bytecode_ptr<NFA> prepEngine(raw_dfa &rdfa, u32 roseQuality,
const CompileContext &cc, const ReportManager &rm,
bool has_literals, u32 *start_offset,
bool has_non_literals, u32 *start_offset,
u32 *small_region) {
*start_offset = remove_leading_dots(rdfa);
// Unleash the McClellan!
set<dstate_id_t> accel_states;
auto nfa = getDfa(rdfa, cc, rm, has_literals, accel_states);
auto nfa = getDfa(rdfa, cc, rm, has_non_literals, accel_states);
if (!nfa) {
DEBUG_PRINTF("DFA compile failed for smallwrite NFA\n");
return nullptr;
@@ -737,7 +739,7 @@ bytecode_ptr<NFA> prepEngine(raw_dfa &rdfa, u32 roseQuality,
return nullptr;
}
nfa = getDfa(rdfa, cc, rm, has_literals, accel_states);
nfa = getDfa(rdfa, cc, rm, has_non_literals, accel_states);
if (!nfa) {
DEBUG_PRINTF("DFA compile failed for smallwrite NFA\n");
assert(0); /* able to build orig dfa but not the trimmed? */
@@ -768,6 +770,7 @@ unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(size_t num_patterns,
bytecode_ptr<SmallWriteEngine> SmallWriteBuildImpl::build(u32 roseQuality) {
const bool has_literals = !is_empty(lit_trie) || !is_empty(lit_trie_nocase);
const bool has_non_literals = rdfa != nullptr;
if (!rdfa && !has_literals) {
DEBUG_PRINTF("no smallwrite engine\n");
poisoned = true;
@@ -788,7 +791,7 @@ bytecode_ptr<SmallWriteEngine> SmallWriteBuildImpl::build(u32 roseQuality) {
u32 start_offset;
u32 small_region;
auto nfa = prepEngine(*rdfa, roseQuality, cc, rm, has_literals,
auto nfa = prepEngine(*rdfa, roseQuality, cc, rm, has_non_literals,
&start_offset, &small_region);
if (!nfa) {
DEBUG_PRINTF("some smallwrite outfix could not be prepped\n");