limex: only compress active repeats

This commit is contained in:
Justin Viiret 2016-07-04 12:56:03 +10:00 committed by Matthew Barr
parent aa54352a3a
commit ae5e347778

View File

@ -363,16 +363,24 @@ void COMPRESS_REPEATS_FN(const IMPL_NFA_T *limex, void *dest, void *src,
char *state_base = (char *)dest + limex->stateSize; char *state_base = (char *)dest + limex->stateSize;
for (u32 i = 0; i < limex->repeatCount; i++) { for (u32 i = 0; i < limex->repeatCount; i++) {
DEBUG_PRINTF("repeat %u\n", i);
const struct NFARepeatInfo *info = GET_NFA_REPEAT_INFO_FN(limex, i); const struct NFARepeatInfo *info = GET_NFA_REPEAT_INFO_FN(limex, i);
const struct RepeatInfo *repeat = getRepeatInfo(info);
if (TESTBIT_STATE(&s, info->cyclicState) && if (!TESTBIT_STATE(&s, info->cyclicState)) {
repeatHasMatch(repeat, &ctrl[i], state_base + info->stateOffset, DEBUG_PRINTF("is dead\n");
offset) == REPEAT_STALE) { continue;
DEBUG_PRINTF("repeat %u is stale\n", i);
CLEARBIT_STATE(&s, info->cyclicState);
} }
const struct RepeatInfo *repeat = getRepeatInfo(info);
if (repeatHasMatch(repeat, &ctrl[i], state_base + info->stateOffset,
offset) == REPEAT_STALE) {
DEBUG_PRINTF("is stale, clearing state\n");
CLEARBIT_STATE(&s, info->cyclicState);
continue;
}
DEBUG_PRINTF("packing state (packedCtrlOffset=%u)\n",
info->packedCtrlOffset);
repeatPack(state_base + info->packedCtrlOffset, repeat, &ctrl[i], repeatPack(state_base + info->packedCtrlOffset, repeat, &ctrl[i],
offset); offset);
} }
@ -398,15 +406,24 @@ void EXPAND_REPEATS_FN(const IMPL_NFA_T *limex, void *dest, const void *src,
return; return;
} }
// Note: we expand all repeats, as they may have *just* had their // Note: state has already been expanded into 'dest'.
// cyclic states switched off a moment ago. TODO: is this required? STATE_T s = LOAD_STATE(dest);
union RepeatControl *ctrl = union RepeatControl *ctrl =
getRepeatControlBase((char *)dest, sizeof(STATE_T)); getRepeatControlBase((char *)dest, sizeof(STATE_T));
const char *state_base = (const char *)src + limex->stateSize; const char *state_base = (const char *)src + limex->stateSize;
for (u32 i = 0; i < limex->repeatCount; i++) { for (u32 i = 0; i < limex->repeatCount; i++) {
DEBUG_PRINTF("repeat %u\n", i);
const struct NFARepeatInfo *info = GET_NFA_REPEAT_INFO_FN(limex, i); const struct NFARepeatInfo *info = GET_NFA_REPEAT_INFO_FN(limex, i);
if (!TESTBIT_STATE(&s, info->cyclicState)) {
DEBUG_PRINTF("is dead\n");
continue;
}
DEBUG_PRINTF("unpacking state (packedCtrlOffset=%u)\n",
info->packedCtrlOffset);
const struct RepeatInfo *repeat = getRepeatInfo(info); const struct RepeatInfo *repeat = getRepeatInfo(info);
repeatUnpack(state_base + info->packedCtrlOffset, repeat, offset, repeatUnpack(state_base + info->packedCtrlOffset, repeat, offset,
&ctrl[i]); &ctrl[i]);