iterator: implement collect with FromIterator

This makes it take advantage of the size hint for pre-allocation.
This commit is contained in:
Daniel Micay
2013-06-24 01:21:32 -04:00
parent 8779be39e1
commit 3ab5ec4b7c
2 changed files with 16 additions and 5 deletions

View File

@@ -2500,6 +2500,17 @@ impl<T> FromIter<T> for ~[T]{
}
}
#[cfg(stage0)]
impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
pub fn from_iterator(iterator: &mut T) -> ~[A] {
let mut xs = ~[];
for iterator.advance |x| {
xs.push(x);
}
xs
}
}
#[cfg(not(stage0))]
impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
pub fn from_iterator(iterator: &mut T) -> ~[A] {