From 13281d5f8aaaed5a9037784f5fa38068f9b7bf65 Mon Sep 17 00:00:00 2001
From: Daniel <kingdread@gmx.de>
Date: Fri, 7 Sep 2018 00:16:44 +0200
Subject: parallelize log searching

---
 src/main.rs | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'src')

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> {
-- 
cgit v1.2.3