Skip to content

Commit 879ebce

Browse files
author
Jorge Aparicio
committed
libcollections: use unboxed closures
1 parent 9b075bc commit 879ebce

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/libcollections/bench.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ use std::rand;
1313
use std::rand::Rng;
1414
use test::Bencher;
1515

16-
pub fn insert_rand_n<M>(n: uint, map: &mut M, b: &mut Bencher,
17-
insert: |&mut M, uint|,
18-
remove: |&mut M, uint|) {
16+
pub fn insert_rand_n<M, I, R>(n: uint,
17+
map: &mut M,
18+
b: &mut Bencher,
19+
mut insert: I,
20+
mut remove: R) where
21+
I: FnMut(&mut M, uint),
22+
R: FnMut(&mut M, uint),
23+
{
1924
// setup
2025
let mut rng = rand::weak_rng();
2126

@@ -31,9 +36,14 @@ pub fn insert_rand_n<M>(n: uint, map: &mut M, b: &mut Bencher,
3136
})
3237
}
3338

34-
pub fn insert_seq_n<M>(n: uint, map: &mut M, b: &mut Bencher,
35-
insert: |&mut M, uint|,
36-
remove: |&mut M, uint|) {
39+
pub fn insert_seq_n<M, I, R>(n: uint,
40+
map: &mut M,
41+
b: &mut Bencher,
42+
mut insert: I,
43+
mut remove: R) where
44+
I: FnMut(&mut M, uint),
45+
R: FnMut(&mut M, uint),
46+
{
3747
// setup
3848
for i in range(0u, n) {
3949
insert(map, i * 2);
@@ -48,9 +58,14 @@ pub fn insert_seq_n<M>(n: uint, map: &mut M, b: &mut Bencher,
4858
})
4959
}
5060

51-
pub fn find_rand_n<M, T>(n: uint, map: &mut M, b: &mut Bencher,
52-
insert: |&mut M, uint|,
53-
find: |&M, uint| -> T) {
61+
pub fn find_rand_n<M, T, I, F>(n: uint,
62+
map: &mut M,
63+
b: &mut Bencher,
64+
mut insert: I,
65+
mut find: F) where
66+
I: FnMut(&mut M, uint),
67+
F: FnMut(&M, uint) -> T,
68+
{
5469
// setup
5570
let mut rng = rand::weak_rng();
5671
let mut keys = Vec::from_fn(n, |_| rng.gen::<uint>() % n);
@@ -70,9 +85,14 @@ pub fn find_rand_n<M, T>(n: uint, map: &mut M, b: &mut Bencher,
7085
})
7186
}
7287

73-
pub fn find_seq_n<M, T>(n: uint, map: &mut M, b: &mut Bencher,
74-
insert: |&mut M, uint|,
75-
find: |&M, uint| -> T) {
88+
pub fn find_seq_n<M, T, I, F>(n: uint,
89+
map: &mut M,
90+
b: &mut Bencher,
91+
mut insert: I,
92+
mut find: F) where
93+
I: FnMut(&mut M, uint),
94+
F: FnMut(&M, uint) -> T,
95+
{
7696
// setup
7797
for i in range(0u, n) {
7898
insert(map, i);

0 commit comments

Comments
 (0)