auto merge of #5867 : dotdash/rust/reduce_reallocs, r=graydon

The foldl based implementation allocates lots of unneeded vectors.
iter::map_to_vec is already optimized to avoid these.

One place that benefits quite a lot from this is the metadata decoder, helping with compile times for tiny programs.
This commit is contained in:
bors 2013-04-13 17:15:55 -07:00
commit 8c2e5cceee

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)]