From d497a1259a1230c47e070ef73084f956dda6b7cd Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Tue, 5 Jul 2016 14:37:22 +1000 Subject: [PATCH] rose: use normal callback for pure-literal cases --- src/rose/match.c | 23 ----------------------- src/rose/rose.h | 3 +-- src/runtime.c | 12 ++++++++++-- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/rose/match.c b/src/rose/match.c index 2b05fd76..15d3534c 100644 --- a/src/rose/match.c +++ b/src/rose/match.c @@ -582,29 +582,6 @@ hwlmcb_rv_t roseFloatingCallback(size_t start, size_t end, u32 id, void *ctxt) { return roseCallback_i(start, end, id, ctxt) & t->floating_group_mask; } -/** - * \brief Match callback adaptor used for matches from pure-literal cases. - * - * Literal match IDs in this path run limited Rose programs that do not use - * Rose state (which is not initialised in the pure-literal path). They can - * still, for example, check lookarounds or literal masks. - */ -hwlmcb_rv_t rosePureLiteralCallback(size_t start, size_t end, u32 id, - void *context) { - DEBUG_PRINTF("start=%zu, end=%zu, id=%u\n", start, end, id); - struct hs_scratch *scratch = context; - struct core_info *ci = &scratch->core_info; - const u64a real_end = (u64a)end + ci->buf_offset + 1; - const u64a som = 0; - const size_t match_len = end - start + 1; - const struct RoseEngine *rose = ci->rose; - const u32 *programs = getByOffset(rose, rose->litProgramOffset); - assert(id < rose->literalCount); - const u8 flags = 0; - return roseRunProgram(rose, scratch, programs[id], som, real_end, match_len, - flags); -} - /** * \brief Execute a boundary report program. * diff --git a/src/rose/rose.h b/src/rose/rose.h index 280e3bd5..9a50f0e9 100644 --- a/src/rose/rose.h +++ b/src/rose/rose.h @@ -46,8 +46,7 @@ void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch); void roseStreamEodExec(const struct RoseEngine *t, u64a offset, struct hs_scratch *scratch); -hwlmcb_rv_t rosePureLiteralCallback(size_t start, size_t end, u32 id, - void *context); +hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *context); int roseReportAdaptor(u64a start, u64a end, ReportID id, void *context); diff --git a/src/runtime.c b/src/runtime.c index 2def17c8..fc867b8e 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -198,7 +198,11 @@ void pureLiteralBlockExec(const struct RoseEngine *rose, size_t length = scratch->core_info.len; DEBUG_PRINTF("rose engine %d\n", rose->runtimeImpl); - hwlmExec(ftable, buffer, length, 0, rosePureLiteralCallback, scratch, + // RoseContext values that need to be set for use by roseCallback. + scratch->tctxt.groups = rose->initialGroups; + scratch->tctxt.lit_offset_adjust = 1; + + hwlmExec(ftable, buffer, length, 0, roseCallback, scratch, rose->initialGroups); } @@ -742,11 +746,15 @@ void pureLiteralStreamExec(struct hs_stream *stream_state, DEBUG_PRINTF("::: streaming rose ::: offset = %llu len = %zu\n", stream_state->offset, scratch->core_info.len); + // RoseContext values that need to be set for use by roseCallback. + scratch->tctxt.groups = loadGroups(rose, scratch->core_info.state); + scratch->tctxt.lit_offset_adjust = scratch->core_info.buf_offset + 1; + // Pure literal cases don't have floatingMinDistance set, so we always // start the match region at zero. const size_t start = 0; - hwlmExecStreaming(ftable, scratch, len2, start, rosePureLiteralCallback, + hwlmExecStreaming(ftable, scratch, len2, start, roseCallback, scratch, rose->initialGroups, hwlm_stream_state); if (!told_to_stop_matching(scratch) &&