From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id EBAA96DE0B64 for ; Wed, 10 May 2017 04:39:23 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4sBwARRz5slf for ; Wed, 10 May 2017 04:39:23 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 5E9136DE091E for ; Wed, 10 May 2017 04:39:23 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1d8Pwr-0000gF-Fz; Wed, 10 May 2017 07:38:29 -0400 Received: (nullmailer pid 28577 invoked by uid 1000); Wed, 10 May 2017 11:39:15 -0000 From: David Bremner To: notmuch@freelists.org, notmuch@notmuchmail.org Subject: [PATCH 5/6] lib/index.cc: generalize filter state machine Date: Wed, 10 May 2017 08:39:09 -0300 Message-Id: <20170510113910.28444-6-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170510113910.28444-1-david@tethera.net> References: <20170510113910.28444-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 May 2017 11:39:24 -0000 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