]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Add q_last_type() queue function
authorJustin Viiret <justin.viiret@intel.com>
Thu, 29 Oct 2015 22:43:28 +0000 (09:43 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 10 Nov 2015 03:25:04 +0000 (14:25 +1100)
Analogous to q_cur_type(), asserts that queue indices are within a valid
range.

src/nfa/nfa_api_queue.h
src/rose/catchup.c
src/rose/match.c
src/rose/stream.c

index d8079292ba45c039e3afa4860049061d38c410ba..75c15ccea373ff0c11977486e86b1d86cc87fce9 100644 (file)
@@ -196,6 +196,14 @@ static really_inline s64a q_cur_loc(const struct mq *q) {
     return q->items[q->cur].location;
 }
 
+/** \brief Returns the type of the last event in the queue. */
+static really_inline u32 q_last_type(const struct mq *q) {
+    assert(q->cur < q->end);
+    assert(q->end > 0);
+    assert(q->end <= MAX_MQE_LEN);
+    return q->items[q->end - 1].type;
+}
+
 /** \brief Returns the location (relative to the beginning of the current data
  * buffer) of the last event in the queue. */
 static really_inline s64a q_last_loc(const struct mq *q) {
index b9fcd78425698fb032f60b4265fd1d8f262f7674..77b12b49f74a8dfa0ac0c85f705ff59dd5074f05 100644 (file)
@@ -379,7 +379,7 @@ void ensureEnd(struct mq *q, UNUSED u32 qi, s64a final_loc) {
     DEBUG_PRINTF("ensure MQE_END %lld for queue %u\n", final_loc, qi);
     if (final_loc >= q_last_loc(q)) {
         /* TODO: ensure situation does not arise */
-        assert(q->items[q->end - 1].type != MQE_END);
+        assert(q_last_type(q) != MQE_END);
         pushQueueNoMerge(q, MQE_END, final_loc);
     }
 }
index 32224c24d8eb8fb19f071a11a5f2af4a8f647be2..be9bc35efeff6039570184c408c9c338ca6250ae 100644 (file)
@@ -758,7 +758,7 @@ found_miracle:
 
     q_skip_forward_to(q, miracle_loc);
 
-    if (q->items[q->end - 1].type == MQE_START) {
+    if (q_last_type(q) == MQE_START) {
         DEBUG_PRINTF("miracle caused infix to die\n");
         return 0;
     }
@@ -853,7 +853,7 @@ char roseTestLeftfix(const struct RoseEngine *t, const struct RoseRole *tr,
         }
     }
 
-    if (q_cur_loc(q) < loc || q->items[q->end - 1].type != MQE_START) {
+    if (q_cur_loc(q) < loc || q_last_type(q) != MQE_START) {
         if (left->infix) {
             if (infixTooOld(q, loc)) {
                 DEBUG_PRINTF("infix %u died of old age\n", ri);
index aab79a2924e1e488738e8e7696098bc8e700e553..b100eeaef244c9e1fc85bacad0b7223a2a54776c 100644 (file)
@@ -167,7 +167,7 @@ found_miracle:
 
         DEBUG_PRINTF("skip q forward, %lld to %lld\n", begin_loc, miracle_loc);
         q_skip_forward_to(q, miracle_loc);
-        if (q->items[q->end - 1].type == MQE_START) {
+        if (q_last_type(q) == MQE_START) {
             DEBUG_PRINTF("miracle caused infix to die\n");
             return MIRACLE_DEAD;
         }