From 173d5ab7f37d75a7f85760b2b0a7de3ac863467a Mon Sep 17 00:00:00 2001
From: Martin Larralde <martin.larralde@embl.de>
Date: Wed, 19 Jun 2024 17:14:29 +0200
Subject: [PATCH] Cache the `Pipeline` used in `lightmotif::scan::Scanner`

---
 lightmotif/src/scan.rs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lightmotif/src/scan.rs b/lightmotif/src/scan.rs
index 329824d..629a59b 100644
--- a/lightmotif/src/scan.rs
+++ b/lightmotif/src/scan.rs
@@ -66,6 +66,7 @@ pub struct Scanner<'a, A: Alphabet> {
     block_size: usize,
     row: usize,
     hits: Vec<Hit>,
+    pipeline: Pipeline<A, Dispatch>,
 }
 
 impl<'a, A: Alphabet> Scanner<'a, A> {
@@ -79,6 +80,7 @@ impl<'a, A: Alphabet> Scanner<'a, A> {
             block_size: 512,
             row: 0,
             hits: Vec::new(),
+            pipeline: Pipeline::dispatch(),
         }
     }
 
@@ -140,12 +142,12 @@ where
     type Item = Hit;
     fn next(&mut self) -> Option<Self::Item> {
         while self.hits.is_empty() && self.row < self.seq.matrix().rows() {
-            let pli = Pipeline::dispatch();
             let end = (self.row + self.block_size)
                 .min(self.seq.matrix().rows().saturating_sub(self.seq.wrap()));
-            pli.score_rows_into(&self.pssm, &self.seq, self.row..end, &mut self.scores);
+            self.pipeline
+                .score_rows_into(&self.pssm, &self.seq, self.row..end, &mut self.scores);
             let matrix = self.scores.matrix();
-            for c in pli.threshold(&self.scores, self.threshold) {
+            for c in self.pipeline.threshold(&self.scores, self.threshold) {
                 let index = c.col * (self.seq.matrix().rows() - self.seq.wrap()) + self.row + c.row;
                 self.hits.push(Hit::new(index, matrix[c]));
             }
-- 
GitLab