scanner: Parallelize the scan process

This commit is contained in:
David Wendt 2021-08-23 19:46:17 -04:00 committed by Mike Welsh
parent f9c646e51f
commit 1d0e418c5c
3 changed files with 22 additions and 10 deletions

1
Cargo.lock generated
View File

@ -3179,6 +3179,7 @@ dependencies = [
"indicatif", "indicatif",
"log", "log",
"path-slash", "path-slash",
"rayon",
"ruffle_core", "ruffle_core",
"serde", "serde",
"swf", "swf",

View File

@ -16,3 +16,4 @@ csv = "1.1"
indicatif = "0.16" indicatif = "0.16"
path-slash = "0.1.4" path-slash = "0.1.4"
swf = { path = "../swf" } swf = { path = "../swf" }
rayon = "1.5.1"

View File

@ -1,6 +1,7 @@
use clap::Clap; use clap::Clap;
use indicatif::{ProgressBar, ProgressStyle}; use indicatif::{ProgressBar, ProgressStyle};
use path_slash::PathExt; use path_slash::PathExt;
use rayon::prelude::*;
use ruffle_core::swf::{decompress_swf, parse_swf}; use ruffle_core::swf::{decompress_swf, parse_swf};
use swf::{FileAttributes, Tag}; use swf::{FileAttributes, Tag};
@ -130,7 +131,7 @@ fn main() -> Result<(), std::io::Error> {
let mut good = 0; let mut good = 0;
let mut bad = 0; let mut bad = 0;
let progress = ProgressBar::new(total); let progress = ProgressBar::new(total);
let mut writer = csv::Writer::from_path(opt.output_path)?; let mut writer = csv::Writer::from_path(opt.output_path.clone())?;
progress.set_style( progress.set_style(
ProgressStyle::default_bar() ProgressStyle::default_bar()
@ -142,16 +143,25 @@ fn main() -> Result<(), std::io::Error> {
writer.write_record(&["Filename", "Error", "AVM Version"])?; writer.write_record(&["Filename", "Error", "AVM Version"])?;
for file in to_scan { let mut results = Vec::new();
to_scan
.into_par_iter()
.map(|file| {
let name = file let name = file
.path() .path()
.strip_prefix(&opt.input_path) .strip_prefix(&opt.input_path)
.unwrap_or_else(|_| file.path()) .unwrap_or_else(|_| file.path())
.to_slash_lossy(); .to_slash_lossy();
progress.inc(1); let result = scan_file(file, name.clone());
progress.set_message(name.clone());
let result = scan_file(file, name);
progress.inc(1);
progress.set_message(name);
result
})
.collect_into_vec(&mut results);
for result in results {
if result.error.is_none() { if result.error.is_none() {
good += 1; good += 1;
} else { } else {