diff --git a/src/hyperfine/benchmark.rs b/src/hyperfine/benchmark.rs index 6ca2845..0841c1a 100644 --- a/src/hyperfine/benchmark.rs +++ b/src/hyperfine/benchmark.rs @@ -147,10 +147,10 @@ pub fn mean_shell_spawning_time( } } - progress_bar.as_ref().map(|bar| bar.inc(1)); + if let Some(bar) = progress_bar.as_ref() { bar.inc(1) } } - progress_bar.as_ref().map(|bar| bar.finish_and_clear()); + if let Some(bar) = progress_bar.as_ref() { bar.finish_and_clear() } Ok(TimingResult { time_real: mean(×_real), @@ -276,9 +276,9 @@ pub fn run_benchmark( options.failure_action, None, )?; - progress_bar.as_ref().map(|bar| bar.inc(1)); + if let Some(bar) = progress_bar.as_ref() { bar.inc(1) } } - progress_bar.as_ref().map(|bar| bar.finish_and_clear()); + if let Some(bar) = progress_bar.as_ref() { bar.finish_and_clear() } } // Set up progress bar (and spinner for initial measurement) @@ -331,8 +331,8 @@ pub fn run_benchmark( all_succeeded = all_succeeded && success; // Re-configure the progress bar - progress_bar.as_ref().map(|bar| bar.set_length(count)); - progress_bar.as_ref().map(|bar| bar.inc(1)); + if let Some(bar) = progress_bar.as_ref() { bar.set_length(count) } + if let Some(bar) = progress_bar.as_ref() { bar.inc(1) } // Gather statistics for _ in 0..count_remaining { @@ -343,9 +343,8 @@ pub fn run_benchmark( format!("Current estimate: {}", mean.to_string().green()) }; - progress_bar - .as_ref() - .map(|bar| bar.set_message(msg.to_owned())); + if let Some(bar) = progress_bar + .as_ref() { bar.set_message(msg.to_owned()) } let (res, status) = time_shell_command( &options.shell, @@ -363,10 +362,10 @@ pub fn run_benchmark( all_succeeded = all_succeeded && success; - progress_bar.as_ref().map(|bar| bar.inc(1)); + if let Some(bar) = progress_bar.as_ref() { bar.inc(1) } } - progress_bar.as_ref().map(|bar| bar.finish_and_clear()); + if let Some(bar) = progress_bar.as_ref() { bar.finish_and_clear() } // Compute statistical quantities let t_num = times_real.len(); diff --git a/src/hyperfine/export/mod.rs b/src/hyperfine/export/mod.rs index 541b1e5..d213dc3 100644 --- a/src/hyperfine/export/mod.rs +++ b/src/hyperfine/export/mod.rs @@ -75,7 +75,7 @@ impl ExportManager { /// Write the given results to all Exporters contained within this manager pub fn write_results(&self, results: &[BenchmarkResult], unit: Option) -> Result<()> { for e in &self.exporters { - let file_content = e.exporter.serialize(&results, unit)?; + let file_content = e.exporter.serialize(results, unit)?; write_to_file(&e.filename, &file_content)?; } Ok(()) diff --git a/src/hyperfine/internal.rs b/src/hyperfine/internal.rs index e3e68c0..26ea2d7 100644 --- a/src/hyperfine/internal.rs +++ b/src/hyperfine/internal.rs @@ -105,7 +105,7 @@ pub fn write_benchmark_comparison(results: &[BenchmarkResult]) { return; } - if let Some(mut annotated_results) = compute_relative_speed(&results) { + if let Some(mut annotated_results) = compute_relative_speed(results) { annotated_results.sort_by(|l, r| compare_mean_time(l.result, r.result)); let fastest = &annotated_results[0]; diff --git a/src/hyperfine/parameter_range.rs b/src/hyperfine/parameter_range.rs index 6b89ec3..55b7aa9 100644 --- a/src/hyperfine/parameter_range.rs +++ b/src/hyperfine/parameter_range.rs @@ -118,8 +118,7 @@ fn build_parameterized_commands<'a, T: Numeric>( for cmd in &command_strings { let name = command_names .get(i) - .or_else(|| command_names.get(0)) - .map(|s| *s); + .or_else(|| command_names.get(0)).copied(); commands.push(Command::new_parametrized( name, cmd, diff --git a/src/hyperfine/types.rs b/src/hyperfine/types.rs index 7a0c4f4..e5f863f 100644 --- a/src/hyperfine/types.rs +++ b/src/hyperfine/types.rs @@ -138,7 +138,7 @@ impl<'a> Command<'a> { 'outer: while let Some(head) = remaining.chars().next() { for (k, v) in &replacements { if remaining.starts_with(k.as_str()) { - result.push_str(&v); + result.push_str(v); remaining = &remaining[k.len()..]; continue 'outer; } diff --git a/src/main.rs b/src/main.rs index 5ebd5c4..f573a72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ fn main() { }; let res = match options { - Ok(ref opts) => run(&commands, &opts, &export_manager), + Ok(ref opts) => run(&commands, opts, &export_manager), Err(ref e) => error(&e.to_string()), }; @@ -270,8 +270,7 @@ fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec> { 'outer: loop { let name = command_names .get(i) - .or_else(|| command_names.get(0)) - .map(|s| *s); + .or_else(|| command_names.get(0)).copied(); i += 1; let (command_index, params_indices) = index.split_first().unwrap(); @@ -309,7 +308,7 @@ fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec> { let command_list = command_strings.collect::>(); let mut commands = Vec::with_capacity(command_list.len()); for (i, s) in command_list.iter().enumerate() { - commands.push(Command::new(command_names.get(i).copied(), &s)); + commands.push(Command::new(command_names.get(i).copied(), s)); } commands }