limex: add CANNOT_DIE flag and loop without test

This commit is contained in:
Justin Viiret 2017-04-03 11:40:42 +10:00 committed by Matthew Barr
parent 7920b1086b
commit 8713cfbd9e
3 changed files with 28 additions and 1 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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) {