[PATCH 5/6] lib/index.cc: generalize filter state machine

David Bremner david at tethera.net
Wed May 10 04:39:09 PDT 2017


To match things more complicated than fixed strings, we need states
with multiple out arrows.
---
 lib/index.cc | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/lib/index.cc b/lib/index.cc
index 3bb1ac1c..1b420b75 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -129,16 +129,23 @@ do_filter (const scanner_state_t states[],
     g_mime_filter_set_size (gmime_filter, inlen, FALSE);
     outptr = gmime_filter->outbuf;
 
+    next = filter->state;
     while (inptr < inend) {
-	if (*inptr >= states[filter->state].a &&
-	    *inptr <= states[filter->state].b)
-	{
-	    next = states[filter->state].next_if_match;
-	}
-	else
-	{
-	    next = states[filter->state].next_if_not_match;
-	}
+	 /* Each state is defined by a contiguous set of rows of the
+	 * state table marked by a common value for '.state'. The
+	 * state numbers must be equal to the index of the first row
+	 * in a given state; thus the loop condition here looks for a
+	 * jump to a first row of a state, which is a real transition
+	 * in the underlying DFA.
+	 */
+	do {
+	    if (*inptr >= states[next].a && *inptr <= states[next].b)  {
+		next = states[next].next_if_match;
+	    } else  {
+		next = states[next].next_if_not_match;
+	    }
+
+	} while (next != states[next].state);
 
 	if (filter->state < first_skipping_state)
 	    *outptr++ = *inptr;
-- 
2.11.0



More information about the notmuch mailing list