@@ -9,7 +9,7 @@ use std::{cmp, env, process};
9
9
use crate :: template:: ANSI_BOLD ;
10
10
use crate :: template:: { aoc_cli, Day , ANSI_ITALIC , ANSI_RESET } ;
11
11
12
- pub fn run_part < I : Clone , T : Display > ( func : impl Fn ( I ) -> Option < T > , input : I , day : Day , part : u8 ) {
12
+ pub fn run_part < I : Copy , T : Display > ( func : impl Fn ( I ) -> Option < T > , input : I , day : Day , part : u8 ) {
13
13
let part_str = format ! ( "Part {part}" ) ;
14
14
15
15
let ( result, duration, samples) =
@@ -25,15 +25,13 @@ pub fn run_part<I: Clone, T: Display>(func: impl Fn(I) -> Option<T>, input: I, d
25
25
/// Run a solution part. The behavior differs depending on whether we are running a release or debug build:
26
26
/// 1. in debug, the function is executed once.
27
27
/// 2. in release, the function is benched (approx. 1 second of execution time or 10 samples, whatever take longer.)
28
- fn run_timed < I : Clone , T > (
28
+ fn run_timed < I : Copy , T > (
29
29
func : impl Fn ( I ) -> T ,
30
30
input : I ,
31
31
hook : impl Fn ( & T ) ,
32
32
) -> ( T , Duration , u128 ) {
33
33
let timer = Instant :: now ( ) ;
34
34
let result = {
35
- let input = input. clone ( ) ;
36
-
37
35
#[ cfg( feature = "dhat-heap" ) ]
38
36
let _profiler = dhat:: Profiler :: new_heap ( ) ;
39
37
@@ -52,7 +50,7 @@ fn run_timed<I: Clone, T>(
52
50
( result, run. 0 , run. 1 )
53
51
}
54
52
55
- fn bench < I : Clone , T > ( func : impl Fn ( I ) -> T , input : I , base_time : & Duration ) -> ( Duration , u128 ) {
53
+ fn bench < I : Copy , T > ( func : impl Fn ( I ) -> T , input : I , base_time : & Duration ) -> ( Duration , u128 ) {
56
54
let mut stdout = stdout ( ) ;
57
55
58
56
print ! ( " > {ANSI_ITALIC}benching{ANSI_RESET}" ) ;
@@ -64,10 +62,8 @@ fn bench<I: Clone, T>(func: impl Fn(I) -> T, input: I, base_time: &Duration) ->
64
62
let mut timers: Vec < Duration > = vec ! [ ] ;
65
63
66
64
for _ in 0 ..bench_iterations {
67
- // need a clone here to make the borrow checker happy.
68
- let cloned = input. clone ( ) ;
69
65
let timer = Instant :: now ( ) ;
70
- black_box ( func ( black_box ( cloned ) ) ) ;
66
+ black_box ( func ( black_box ( input ) ) ) ;
71
67
timers. push ( timer. elapsed ( ) ) ;
72
68
}
73
69
0 commit comments