@@ -16,18 +16,21 @@ impl Search {
16
16
} else {
17
17
std:: path:: Path :: new ( "." ) . to_owned ( )
18
18
} ;
19
- search_path ( & path, self , sender. clone ( ) ) ;
19
+ return rayon:: scope ( |s| {
20
+ s. spawn ( |_| search_path ( & path, self , sender) ) ;
21
+ receive_paths ( receiver, self )
22
+ } ) ;
20
23
}
21
24
// Check if paths are valid and canonicalize if necessary
22
25
let dirs = self . dirs . iter ( ) . map ( |path| {
23
26
if !path. exists ( ) {
24
- eprintln ! ( "ERROR : The {:?} directory does not exist" , path) ;
27
+ eprintln ! ( "Error : The {:?} directory does not exist" , path) ;
25
28
std:: process:: exit ( 1 )
26
29
}
27
30
28
31
if self . canonicalize {
29
32
std:: borrow:: Cow :: Owned ( path. canonicalize ( ) . unwrap_or_else ( |_| {
30
- eprintln ! ( "ERROR : The {:?} directory does not exist" , path) ;
33
+ eprintln ! ( "Error : The {:?} directory does not exist" , path) ;
31
34
std:: process:: exit ( 1 )
32
35
} ) )
33
36
} else {
@@ -57,7 +60,7 @@ impl std::fmt::Display for SearchResult {
57
60
fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
58
61
match self {
59
62
SearchResult :: Exact ( p) => write ! ( f, "{}" , p. display( ) ) ,
60
- SearchResult :: Contains ( s) => write ! ( f , "{}" , s) ,
63
+ SearchResult :: Contains ( s) => f . write_str ( s) ,
61
64
}
62
65
}
63
66
}
@@ -66,12 +69,8 @@ fn receive_paths(receiver: Receiver, search: &Search) -> Buffers {
66
69
let stdout = std:: io:: stdout ( ) ;
67
70
let mut stdout = std:: io:: BufWriter :: new ( stdout. lock ( ) ) ;
68
71
69
- crate :: perf! {
70
- ctx = "alloc vecs" ;
71
-
72
- let mut exact = Vec :: with_capacity( 8 ) ;
73
- let mut contains = Vec :: with_capacity( 8 ) ;
74
- }
72
+ let mut exact = Vec :: with_capacity ( 8 ) ;
73
+ let mut contains = Vec :: with_capacity ( 8 ) ;
75
74
76
75
while let Ok ( path) = receiver. recv ( ) {
77
76
crate :: perf! {
@@ -99,7 +98,6 @@ fn search_path(dir: &Path, search: &Search, sender: Sender) {
99
98
read. flatten ( )
100
99
. par_bridge ( )
101
100
. for_each ( |entry| search_dir ( entry, search, sender. clone ( ) ) ) ;
102
- // return par_fold(read.flatten(), |entry| search_dir(entry, search, sender.clone()));
103
101
} else if search. verbose {
104
102
eprintln ! ( "Could not read {:?}" , dir) ;
105
103
}
@@ -145,12 +143,12 @@ fn search_dir(entry: std::fs::DirEntry, search: &Search, sender: Sender) {
145
143
if starts && ends && ftype {
146
144
// If file name is equal to search name, write it to the "Exact" buffer
147
145
if sname == search. name {
148
- crate :: perf! { ctx = "send_ex" ; sender. send( SearchResult :: Exact ( path. clone( ) ) ) . unwrap( ) ; }
146
+ sender. send ( SearchResult :: Exact ( path. clone ( ) ) ) . unwrap ( ) ;
149
147
}
150
148
// If file name contains the search name, write it to the "Contains" buffer
151
149
else if !search. exact && sname. contains ( & search. name ) {
152
150
let s = crate :: print:: format_with_highlight ( & fname, & sname, & path, search) ;
153
- crate :: perf! { ctx = "send" ; sender. send( SearchResult :: Contains ( s) ) . unwrap( ) ; }
151
+ sender. send ( SearchResult :: Contains ( s) ) . unwrap ( ) ;
154
152
}
155
153
}
156
154
0 commit comments