Skip to content

Commit 431d64d

Browse files
author
mendelsshop
committed
cargo formatted: library:
more parllesim
1 parent 5c7a6a0 commit 431d64d

File tree

1 file changed

+58
-64
lines changed
  • git-function-history-lib/src

1 file changed

+58
-64
lines changed

git-function-history-lib/src/lib.rs

Lines changed: 58 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ use ra_ap_syntax::{
1919
ast::{self, HasDocComments, HasGenericParams, HasName},
2020
AstNode, SourceFile, SyntaxKind,
2121
};
22-
use rayon::{prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator, ParallelExtend}, str::ParallelString, slice::ParallelSliceMut};
22+
use rayon::{
23+
prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelExtend, ParallelIterator},
24+
slice::ParallelSliceMut,
25+
str::ParallelString,
26+
};
2327

2428
use std::{collections::HashMap, error::Error, process::Command};
2529
pub use types::{
@@ -184,73 +188,65 @@ pub fn get_function_history(
184188
if !path.ends_with(".rs") {
185189
return Err("not a rust file")?;
186190
}
187-
file_history.commit_history.par_extend(
188-
commits
189-
.par_iter()
190-
.filter_map(move |commit| {
191-
match find_function_in_commit(commit.0, &path, name) {
192-
Ok(contents) => {
193-
// file_history.commit_history.push(
194-
Some(CommitFunctions::new(
195-
commit.0.to_string(),
196-
vec![File::new(path.to_string(), contents)],
197-
commit.1,
198-
commit.2.to_string(),
199-
commit.3.to_string(),
200-
commit.4.to_string(),
201-
))
202-
}
203-
Err(_) => None,
191+
file_history
192+
.commit_history
193+
.par_extend(commits.par_iter().filter_map(move |commit| {
194+
match find_function_in_commit(commit.0, &path, name) {
195+
Ok(contents) => {
196+
// file_history.commit_history.push(
197+
Some(CommitFunctions::new(
198+
commit.0.to_string(),
199+
vec![File::new(path.to_string(), contents)],
200+
commit.1,
201+
commit.2.to_string(),
202+
commit.3.to_string(),
203+
commit.4.to_string(),
204+
))
204205
}
205-
})
206-
);
206+
Err(_) => None,
207+
}
208+
}));
207209
}
208210

209211
FileType::Relative(ref path) => {
210212
if !path.ends_with(".rs") {
211213
return Err("not a rust file")?;
212214
}
213-
file_history.commit_history.par_extend(
214-
commits
215-
.par_iter()
216-
.filter_map(|commit| {
217-
match find_function_in_commit_with_filetype(commit.0, name, &file) {
218-
Ok(contents) => Some(CommitFunctions::new(
219-
commit.0.to_string(),
220-
contents,
221-
commit.1,
222-
commit.2.to_string(),
223-
commit.3.to_string(),
224-
commit.4.to_string(),
225-
)),
226-
Err(_) => {
227-
// err = e.to_string();
228-
None
229-
}
215+
file_history
216+
.commit_history
217+
.par_extend(commits.par_iter().filter_map(|commit| {
218+
match find_function_in_commit_with_filetype(commit.0, name, &file) {
219+
Ok(contents) => Some(CommitFunctions::new(
220+
commit.0.to_string(),
221+
contents,
222+
commit.1,
223+
commit.2.to_string(),
224+
commit.3.to_string(),
225+
commit.4.to_string(),
226+
)),
227+
Err(_) => {
228+
// err = e.to_string();
229+
None
230230
}
231-
})
232-
233-
);
231+
}
232+
}));
234233
}
235234

236235
FileType::None | FileType::Directory(_) => {
237236
file_history.commit_history.par_extend(
238-
commits
239-
.par_iter()
240-
.filter_map(|commit| {
241-
match find_function_in_commit_with_filetype(commit.0, name, &file) {
242-
Ok(contents) => Some(CommitFunctions::new(
243-
commit.0.to_string(),
244-
contents,
245-
commit.1,
246-
commit.2.to_string(),
247-
commit.3.to_string(),
248-
commit.4.to_string(),
249-
)),
250-
Err(_) => None,
251-
}
252-
})
253-
// .collect::<Vec<_>>(),
237+
commits.par_iter().filter_map(
238+
|commit| match find_function_in_commit_with_filetype(commit.0, name, &file) {
239+
Ok(contents) => Some(CommitFunctions::new(
240+
commit.0.to_string(),
241+
contents,
242+
commit.1,
243+
commit.2.to_string(),
244+
commit.3.to_string(),
245+
commit.4.to_string(),
246+
)),
247+
Err(_) => None,
248+
},
249+
), // .collect::<Vec<_>>(),
254250
);
255251
}
256252
}
@@ -585,14 +581,12 @@ fn find_function_in_commit_with_filetype(
585581
}
586582
let err = "no function found".to_string();
587583
let mut returns = Vec::new();
588-
returns.par_extend(
589-
files
590-
.par_iter()
591-
.filter_map(|file| match find_function_in_commit(commit, file, name) {
592-
Ok(functions) => Some(File::new((*file).to_string(), functions)),
593-
Err(_) => None,
594-
})
595-
);
584+
returns.par_extend(files.par_iter().filter_map(|file| {
585+
match find_function_in_commit(commit, file, name) {
586+
Ok(functions) => Some(File::new((*file).to_string(), functions)),
587+
Err(_) => None,
588+
}
589+
}));
596590
if returns.is_empty() {
597591
Err(err)?;
598592
}

0 commit comments

Comments
 (0)