diff --git a/src/lib.rs b/src/lib.rs index f4179808..938fbd6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -784,19 +784,25 @@ fn perform_reductions( try_alpha_reductions(png, &opts.alphas, eval); } +struct DeadlineImp { + start: Instant, + timeout: Duration, + print_message: AtomicBool, +} + /// Keep track of processing timeout pub(crate) struct Deadline { - start: Instant, - timeout: Option, - print_message: AtomicBool, + imp: Option, } impl Deadline { pub fn new(timeout: Option, verbose: bool) -> Self { Self { - start: Instant::now(), - timeout, - print_message: AtomicBool::new(verbose), + imp: timeout.map(|timeout| DeadlineImp { + start: Instant::now(), + timeout, + print_message: AtomicBool::new(verbose), + }) } } @@ -804,11 +810,11 @@ impl Deadline { /// /// If the verbose option is on, it also prints a timeout message once. pub fn passed(&self) -> bool { - if let Some(timeout) = self.timeout { - let elapsed = self.start.elapsed(); - if elapsed > timeout { - if self.print_message.load(Ordering::Relaxed) { - self.print_message.store(false, Ordering::Relaxed); + if let Some(imp) = &self.imp { + let elapsed = imp.start.elapsed(); + if elapsed > imp.timeout { + if imp.print_message.load(Ordering::Relaxed) { + imp.print_message.store(false, Ordering::Relaxed); eprintln!("Timed out after {} second(s)", elapsed.as_secs()); } return true;