move the reverse into the iterator

This commit is contained in:
Niko Matsakis 2015-08-21 14:47:02 -04:00
parent 63eedfcf53
commit 57909f7068

View File

@ -211,7 +211,7 @@ pub fn minimal_upper_bounds(&self, a: &T, b: &T) -> Vec<&T> {
// - In the example above, we would reverse to // - In the example above, we would reverse to
// `[z, y, x]` and then pare down to `[z]`. // `[z, y, x]` and then pare down to `[z]`.
// 4. Reverse once more just so that we yield a vector in // 4. Reverse once more just so that we yield a vector in
// increasing order of index. Maybe this is silly. // increasing order of index. Not necessary, but why not.
// //
// I believe this algorithm yields a minimal set. The // I believe this algorithm yields a minimal set. The
// argument is that, after step 2, we know that no element // argument is that, after step 2, we know that no element
@ -224,11 +224,11 @@ pub fn minimal_upper_bounds(&self, a: &T, b: &T) -> Vec<&T> {
pare_down(&mut candidates, closure); // (2) pare_down(&mut candidates, closure); // (2)
candidates.reverse(); // (3a) candidates.reverse(); // (3a)
pare_down(&mut candidates, closure); // (3b) pare_down(&mut candidates, closure); // (3b)
candidates.reverse(); // (4)
candidates candidates
}); });
lub_indices.into_iter() lub_indices.into_iter()
.rev() // (4)
.map(|i| &self.elements[i]) .map(|i| &self.elements[i])
.collect() .collect()
} }