|
1 | 1 | use anyhow::{anyhow, Context, Result}; |
2 | | -use aho_corasick::{AhoCorasick, AhoCorasickBuilder}; |
| 2 | +use aho_corasick::AhoCorasickBuilder; |
3 | 3 | use crossbeam_channel::{bounded, Receiver, Sender}; |
4 | 4 | use ignore::WalkBuilder; |
5 | | -use once_cell::sync::OnceCell; |
6 | 5 | use rayon::prelude::*; |
7 | 6 | use regex::Regex; |
8 | 7 | use serde::{Deserialize, Serialize}; |
9 | | -use std::collections::{BTreeMap, BTreeSet}; |
| 8 | +use std::collections::BTreeSet; |
10 | 9 | use std::fs; |
11 | | -use std::io::{self, Read}; |
| 10 | +use std::io::Read; |
12 | 11 | use std::path::{Path, PathBuf}; |
13 | 12 | use std::sync::Arc; |
14 | | -use std::time::{Duration, SystemTime}; |
15 | 13 |
|
16 | 14 | // ---------------- Types ---------------- |
17 | 15 |
|
@@ -92,13 +90,12 @@ pub trait Detector: Send + Sync { |
92 | 90 | pub struct Emitter { |
93 | 91 | tx: Sender<Finding>, |
94 | 92 | rx: Receiver<Finding>, |
95 | | - buffer: Vec<Finding>, |
96 | 93 | } |
97 | 94 |
|
98 | 95 | impl Emitter { |
99 | 96 | pub fn new(bound: usize) -> Self { |
100 | 97 | let (tx, rx) = bounded(bound); |
101 | | - Self { tx, rx, buffer: Vec::new() } |
| 98 | + Self { tx, rx } |
102 | 99 | } |
103 | 100 |
|
104 | 101 | pub fn send(&mut self, finding: Finding) -> Result<()> { |
@@ -497,7 +494,7 @@ impl<'a> Scanner<'a> { |
497 | 494 | for root in roots { |
498 | 495 | let mut builder = WalkBuilder::new(root); |
499 | 496 | builder.hidden(false).git_ignore(true).git_exclude(true).ignore(true); |
500 | | - for ig in &self.config.include_globs { builder.add("."); builder.filter_entry(|_| true); } |
| 497 | + for _ig in &self.config.include_globs { builder.add("."); builder.filter_entry(|_| true); } |
501 | 498 | // exclude_globs are handled later using globset for simplicity |
502 | 499 | for result in builder.build() { |
503 | 500 | if let Ok(entry) = result { |
@@ -545,7 +542,7 @@ impl<'a> Scanner<'a> { |
545 | 542 | if let Ok(bytes) = Self::load_file(path) { |
546 | 543 | let unit = ScanUnit { path: path.clone(), lang, bytes: bytes.clone() }; |
547 | 544 | let stripped = strip_comments(lang, &bytes); |
548 | | - let mut em = Emitter { tx: tx.clone(), rx: rx.clone(), buffer: Vec::new() }; |
| 545 | + let mut em = Emitter { tx: tx.clone(), rx: rx.clone() }; |
549 | 546 | for det in &self.detectors { |
550 | 547 | if !det.languages().contains(&lang) { continue; } |
551 | 548 | if !prefilter_hit(det, &stripped) { continue; } |
@@ -594,25 +591,13 @@ pub struct PatternDetector { |
594 | 591 | id: &'static str, |
595 | 592 | languages: &'static [Language], |
596 | 593 | registry: Arc<PatternRegistry>, |
597 | | - ac: OnceCell<AhoCorasick>, |
598 | 594 | } |
599 | 595 |
|
600 | 596 | impl PatternDetector { |
601 | 597 | pub fn new(id: &'static str, languages: &'static [Language], registry: Arc<PatternRegistry>) -> Self { |
602 | | - Self { id, languages, registry, ac: OnceCell::new() } |
| 598 | + Self { id, languages, registry } |
603 | 599 | } |
604 | 600 |
|
605 | | - fn build_ac(&self) -> AhoCorasick { |
606 | | - // Merge all substrings for relevant libs |
607 | | - let mut subs = BTreeSet::new(); |
608 | | - for lib in self.registry.for_language(self.languages[0]) { // languages are same category per detector |
609 | | - for s in &lib.prefilter_substrings { subs.insert(s.clone()); } |
610 | | - } |
611 | | - AhoCorasickBuilder::new() |
612 | | - .ascii_case_insensitive(true) |
613 | | - .build(subs.into_iter().collect::<Vec<_>>()) |
614 | | - .expect("failed to build aho-corasick for detector") |
615 | | - } |
616 | 601 | } |
617 | 602 |
|
618 | 603 | impl Detector for PatternDetector { |
|
0 commit comments