about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorblake2-ppc <blake2-ppc>2013-08-12 18:39:19 +0200
committerblake2-ppc <blake2-ppc>2013-08-15 02:52:55 +0200
commit6fe4c871f1010053092a908d75ae8e4c4fb46599 (patch)
treeed792a27a8fef56bede8360f7c4e2939d13fd73c /src/libstd
parenta5f9494199c0990002b52c29fed998c5753f4a0b (diff)
downloadrust-6fe4c871f1010053092a908d75ae8e4c4fb46599.tar.gz
rust-6fe4c871f1010053092a908d75ae8e4c4fb46599.zip
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.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/either.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libstd/either.rs b/src/libstd/either.rs
index 7150430893b..5d988965e8c 100644
--- a/src/libstd/either.rs
+++ b/src/libstd/either.rs
@@ -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),