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:
parent
d57aaae025
commit
a26d9db95f
1 changed files with 1 additions and 1 deletions
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue