mirror of
https://github.com/132nd-vWing/tacview-splitter.git
synced 2026-08-26 07:58:36 +02:00
parallelize with rayon
This commit is contained in:
@@ -6,6 +6,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
zip = {version = ">= 0.6.2", default-features = false, features = ["deflate"]}
|
zip = {version = ">= 0.6.2", default-features = false, features = ["deflate"]}
|
||||||
|
rayon = "*"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|||||||
+15
-15
@@ -4,7 +4,9 @@ mod reader;
|
|||||||
mod tacview;
|
mod tacview;
|
||||||
mod writer;
|
mod writer;
|
||||||
|
|
||||||
|
use rayon::prelude::*;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{tacview::Coalition, writer::StringWriter};
|
use crate::{tacview::Coalition, writer::StringWriter};
|
||||||
|
|
||||||
@@ -22,22 +24,20 @@ fn main_inner() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let lines = reader::read_data(&input_filename, is_zip)?;
|
let lines = reader::read_data(&input_filename, is_zip)?;
|
||||||
let (header, body) = processor::split_into_header_and_body(&lines)?;
|
let (header, body) = processor::split_into_header_and_body(&lines)?;
|
||||||
|
|
||||||
let coalition_per_line = processor::divide_body_by_coalition(body)?;
|
let coalition_per_line = Arc::new(processor::divide_body_by_coalition(body)?);
|
||||||
|
let header = Arc::new(header);
|
||||||
|
let body = Arc::new(body);
|
||||||
|
|
||||||
// for c in &coalition_per_line {
|
let _: Vec<_> = vec![Coalition::Blue, Coalition::Red, Coalition::Purple]
|
||||||
// println!("{c}");
|
.into_par_iter()
|
||||||
// }
|
.map(|c| {
|
||||||
|
let mut writer = writer::create_writer(is_zip, &input_filename.clone(), &c).unwrap();
|
||||||
|
writer.write_strings(&header).unwrap();
|
||||||
|
writer
|
||||||
|
.write_for_coalition(&body, &coalition_per_line.clone(), c)
|
||||||
|
.unwrap();
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
let mut blue_writer = writer::create_writer(is_zip, &input_filename, &Coalition::Blue)?;
|
|
||||||
blue_writer.write_strings(header)?;
|
|
||||||
blue_writer.write_for_coalition(body, &coalition_per_line, Coalition::Blue)?;
|
|
||||||
|
|
||||||
let mut red_writer = writer::create_writer(is_zip, &input_filename, &Coalition::Red)?;
|
|
||||||
red_writer.write_strings(header)?;
|
|
||||||
red_writer.write_for_coalition(body, &coalition_per_line, Coalition::Red)?;
|
|
||||||
|
|
||||||
let mut purple_writer = writer::create_writer(is_zip, &input_filename, &Coalition::Purple)?;
|
|
||||||
purple_writer.write_strings(header)?;
|
|
||||||
purple_writer.write_for_coalition(body, &coalition_per_line, Coalition::Purple)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user