Skip to content

Commit 15d54d6

Browse files
author
blake2-ppc
committed
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.
1 parent f70737c commit 15d54d6

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/librustc/metadata/creader.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn read_crates(diag: @mut span_handler,
5757
warn_if_multiple_versions(e, diag, *e.crate_cache);
5858
}
5959

60+
#[deriving(Clone)]
6061
struct cache_entry {
6162
cnum: int,
6263
span: span,
@@ -76,22 +77,13 @@ fn dump_crates(crate_cache: &[cache_entry]) {
7677
fn warn_if_multiple_versions(e: @mut Env,
7778
diag: @mut span_handler,
7879
crate_cache: &[cache_entry]) {
79-
use std::either::*;
80-
8180
if crate_cache.len() != 0u {
8281
let name = loader::crate_name_from_metas(
8382
*crate_cache[crate_cache.len() - 1].metas
8483
);
8584

86-
let vec: ~[Either<cache_entry, cache_entry>] = crate_cache.iter().map(|&entry| {
87-
let othername = loader::crate_name_from_metas(*entry.metas);
88-
if name == othername {
89-
Left(entry)
90-
} else {
91-
Right(entry)
92-
}
93-
}).collect();
94-
let (matches, non_matches) = partition(vec);
85+
let (matches, non_matches) = crate_cache.partitioned(|entry|
86+
name == loader::crate_name_from_metas(*entry.metas));
9587

9688
assert!(!matches.is_empty());
9789

src/libstd/either.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ pub fn rights<L, R, Iter: Iterator<Either<L, R>>>(eithers: Iter)
151151
/// Returns a structure containing a vector of left values and a vector of
152152
/// right values.
153153
pub fn partition<L, R>(eithers: ~[Either<L, R>]) -> (~[L], ~[R]) {
154-
let mut lefts: ~[L] = ~[];
155-
let mut rights: ~[R] = ~[];
154+
let n_lefts = eithers.iter().count(|elt| elt.is_left());
155+
let mut lefts = vec::with_capacity(n_lefts);
156+
let mut rights = vec::with_capacity(eithers.len() - n_lefts);
156157
for elt in eithers.move_iter() {
157158
match elt {
158159
Left(l) => lefts.push(l),

0 commit comments

Comments
 (0)