Update either::partition

Remove the only use of either::partition since it was better
accomplished with vector methods.

Update either::partition so that it sizes the vectors correctly before
it starts.
This commit is contained in:
blake2-ppc 2013-08-12 18:39:19 +02:00
parent a5f9494199
commit 6fe4c871f1
2 changed files with 6 additions and 13 deletions

View file

@ -151,8 +151,9 @@ pub fn rights<L, R, Iter: Iterator<Either<L, R>>>(eithers: Iter)
/// Returns a structure containing a vector of left values and a vector of
/// right values.
pub fn partition<L, R>(eithers: ~[Either<L, R>]) -> (~[L], ~[R]) {
let mut lefts: ~[L] = ~[];
let mut rights: ~[R] = ~[];
let n_lefts = eithers.iter().count(|elt| elt.is_left());
let mut lefts = vec::with_capacity(n_lefts);
let mut rights = vec::with_capacity(eithers.len() - n_lefts);
for elt in eithers.move_iter() {
match elt {
Left(l) => lefts.push(l),