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:
parent
a5f9494199
commit
6fe4c871f1
2 changed files with 6 additions and 13 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue