process_files on a slice

This commit is contained in:
Dmitry Belyaev 2019-07-27 11:06:04 +03:00
parent d878182c56
commit ce92ec5e87
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -219,7 +219,7 @@ fn split_vec<'a, T>(src: &'a [T], num: usize) -> Vec<&'a [T]> {
result result
} }
fn process_files(files: Vec<PathBuf>) { fn process_files(files: &&[PathBuf]) {
let zip_file = fs::File::open(BASE_FILENAME).unwrap(); let zip_file = fs::File::open(BASE_FILENAME).unwrap();
let zip_reader = io::BufReader::new(zip_file); let zip_reader = io::BufReader::new(zip_file);
let mut archive = zip::ZipArchive::new(zip_reader).unwrap(); let mut archive = zip::ZipArchive::new(zip_reader).unwrap();
@ -264,13 +264,9 @@ fn main() -> Result<(), Box<std::error::Error>> {
.collect(); .collect();
drop(archive); drop(archive);
//split vector and iterate on it parts in parallel // split vector and process its parts in parallel
split_vec(&source_files, rayon::current_num_threads()) split_vec(&source_files, rayon::current_num_threads())
.par_iter() .par_iter()
.for_each(|slice| { .for_each(process_files);
let source_files_part = slice.to_vec();
process_files(source_files_part);
});
Ok(()) Ok(())
} }