Avoid excessive allocations and copies in iter::to_vec

The foldl based implementation allocates lots of unneeded vectors.
iter::map_to_vec is already optimized to avoid these.
This commit is contained in:
Björn Steinbrink 2013-04-12 19:21:46 +02:00
parent d57aaae025
commit a26d9db95f

View file

@ -161,7 +161,7 @@ pub fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B, blk: &fn(&B, &A) -> B)
#[inline(always)]
pub fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a]))
map_to_vec(self, |&x| x)
}
#[inline(always)]