Skip to content

Commit 74d2731

Browse files
committed
remove useless Iterate impl, and permute the order of the argument of iterate
Writing iterate(x, f) is more logical as rust iterator pipeline is left to right.
1 parent 89a9ce0 commit 74d2731

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/test/bench/shootout-meteor.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,13 @@
1414

1515
// returns an infinite iterator of repeated applications of f to x,
1616
// i.e. [x, f(x), f(f(x)), ...], as haskell iterate function.
17-
fn iterate<'a, T>(f: &'a fn(&T) -> T, x: T) -> Iterate<'a, T> {
18-
Iterate::new(f, x)
17+
fn iterate<'a, T>(x: T, f: &'a fn(&T) -> T) -> Iterate<'a, T> {
18+
Iterate {f: f, next: x}
1919
}
2020
struct Iterate<'self, T> {
2121
priv f: &'self fn(&T) -> T,
2222
priv next: T
2323
}
24-
impl<'self, T> Iterate<'self, T> {
25-
fn new<'a>(f: &'a fn(&T) -> T, x: T) -> Iterate<'a, T> {
26-
Iterate {f: f, next: x}
27-
}
28-
}
2924
impl<'self, T> Iterator<T> for Iterate<'self, T> {
3025
fn next(&mut self) -> Option<T> {
3126
let mut res = (self.f)(&self.next);
@@ -71,11 +66,11 @@ impl<'self, T> Iterator<&'self T> for ListIterator<'self, T> {
7166
fn transform(p: ~[(int, int)], all: bool) -> ~[~[(int, int)]] {
7267
let mut res =
7368
// rotations
74-
iterate(|p| p.iter().map(|&(y, x)| (x + y, -y)).collect(), p)
69+
iterate(p, |p| p.iter().map(|&(y, x)| (x + y, -y)).collect())
7570
.take(if all {6} else {3})
7671
// mirror
7772
.flat_map(|p| {
78-
iterate(|p| p.iter().map(|&(y, x)| (x, y)).collect(), p).take(2)
73+
iterate(p, |p| p.iter().map(|&(y, x)| (x, y)).collect()).take(2)
7974
}).to_owned_vec();
8075

8176
// translating to (0, 0) as minimum coordinates.

0 commit comments

Comments
 (0)