Skip to content

Commit 85d599e

Browse files
committed
feat: enable concurrent icon saving using threads
1 parent 5e938ef commit 85d599e

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/main.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
fs::{self},
33
path,
4+
sync::Arc,
45
};
56

67
use clap::{CommandFactory, Parser};
@@ -123,20 +124,29 @@ fn core(args: ToIconArgs) -> bool {
123124
return false;
124125
}
125126

126-
let mut ok = true;
127+
let img = Arc::new(img);
128+
129+
let mut handles = vec![];
130+
131+
{
132+
let save_path = output_dir.join(format!("{output}.ico"));
133+
let img_clone = Arc::clone(&img);
134+
let handle =
135+
thread::spawn(move || save_icon(&*img_clone, &save_path, args.size.into(), args.force));
136+
handles.push(handle);
137+
}
127138

128139
let sizes = [16, 24, 32, 48, 64, 128, 256];
129140
for size in sizes {
130141
let save_path = output_dir.join(format!("{output}_{size}.ico"));
131-
ok = save_icon(&img, &save_path, size, args.force) && ok;
132-
133-
if size == args.size.into() {
134-
let save_path = output_dir.join(format!("{output}.ico"));
135-
ok = save_icon(&img, &save_path, size, args.force) && ok;
136-
}
142+
let img_clone = Arc::clone(&img);
143+
let handle = thread::spawn(move || save_icon(&*img_clone, &save_path, size, args.force));
144+
handles.push(handle);
137145
}
138146

139-
return ok;
147+
handles
148+
.into_iter()
149+
.fold(true, |acc, handle| handle.join().unwrap_or(false) && acc)
140150
}
141151

142152
/// # Returns

0 commit comments

Comments
 (0)