diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 13 |
2 files changed, 9 insertions, 5 deletions
@@ -11,3 +11,4 @@ walkdir = "2" quick-error = "1" colored = "1" chrono = "0.4" +rayon = "1"
\ No newline at end of file diff --git a/src/main.rs b/src/main.rs index c776336..29f482f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ extern crate colored; extern crate evtclib; extern crate regex; extern crate walkdir; +extern crate rayon; use std::fs::File; use std::io::{self, BufReader}; @@ -17,6 +18,8 @@ use regex::Regex; use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; +use rayon::prelude::*; + use evtclib::{AgentKind, AgentName, EventKind, Log}; mod errors; @@ -103,16 +106,16 @@ fn is_log_file(entry: &DirEntry) -> bool { fn grep(opt: &Opt) -> Result<(), RuntimeError> { let walker = WalkDir::new(&opt.path); - for entry in walker { - let entry = entry?; + let entries = walker.into_iter().collect::<Vec<_>>(); + entries.into_par_iter().try_for_each(|e| { + let entry = e?; if is_log_file(&entry) { if let Some(result) = search_log(&entry, opt)? { output::colored(io::stdout(), &result)?; } } - } - - Ok(()) + Ok(()) + }) } fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeError> { |