From 8713cfbd9e0764d4a30c4b6127948c0ab761fb64 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Mon, 3 Apr 2017 11:40:42 +1000 Subject: [PATCH] limex: add CANNOT_DIE flag and loop without test --- src/nfa/limex_compile.cpp | 4 ++++ src/nfa/limex_internal.h | 1 + src/nfa/limex_runtime_impl.h | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/nfa/limex_compile.cpp b/src/nfa/limex_compile.cpp index e064420d..92ec4205 100644 --- a/src/nfa/limex_compile.cpp +++ b/src/nfa/limex_compile.cpp @@ -2237,6 +2237,10 @@ struct Factory { limex->shiftCount = shiftCount; writeShiftMasks(args, limex); + if (hasInitDsStates(args.h, args.state_ids)) { + setLimexFlag(limex, LIMEX_FLAG_CANNOT_DIE); + } + // Determine the state required for our state vector. findStateSize(args, limex); diff --git a/src/nfa/limex_internal.h b/src/nfa/limex_internal.h index ccbf3422..db703f03 100644 --- a/src/nfa/limex_internal.h +++ b/src/nfa/limex_internal.h @@ -85,6 +85,7 @@ #define LIMEX_FLAG_COMPRESS_STATE 1 /**< pack state into stream state */ #define LIMEX_FLAG_COMPRESS_MASKED 2 /**< use reach mask-based compression */ +#define LIMEX_FLAG_CANNOT_DIE 4 /**< limex cannot have no states on */ enum LimExTrigger { LIMEX_TRIGGER_NONE = 0, diff --git a/src/nfa/limex_runtime_impl.h b/src/nfa/limex_runtime_impl.h index ca761924..b9002c91 100644 --- a/src/nfa/limex_runtime_impl.h +++ b/src/nfa/limex_runtime_impl.h @@ -216,11 +216,32 @@ char STREAM_FN(const IMPL_NFA_T *limex, const u8 *input, size_t length, size_t min_accel_offset = 0; if (!limex->accelCount || length < ACCEL_MIN_LEN) { min_accel_offset = length; - goto without_accel; + if (limex->flags & LIMEX_FLAG_CANNOT_DIE) { + goto cannot_die; + } else { + goto without_accel; + } } else { goto with_accel; } +cannot_die: + for (; i != min_accel_offset; i++) { + DUMP_INPUT(i); + + STATE_T succ; + NFA_EXEC_GET_LIM_SUCC(limex, s, succ); + + if (RUN_EXCEPTIONS_FN(limex, exceptions, s, EXCEPTION_MASK, i, offset, + &succ, final_loc, ctx, flags, 0, first_match)) { + return MO_HALT_MATCHING; + } + + u8 c = input[i]; + s = AND_STATE(succ, LOAD_FROM_ENG(&reach[limex->reachMap[c]])); + } + goto finished; + without_accel: for (; i != min_accel_offset; i++) { DUMP_INPUT(i); @@ -292,6 +313,7 @@ with_accel: s = AND_STATE(succ, LOAD_FROM_ENG(&reach[limex->reachMap[c]])); } +finished: ctx->s = s; if ((first_match || (flags & CALLBACK_OUTPUT)) && limex->acceptCount) {