Skip to content

Commit 8c2e5cc

Browse files
committed
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.
2 parents 04cc836 + a26d9db commit 8c2e5cc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B, blk: &fn(&B, &A) -> B)
161161

162162
#[inline(always)]
163163
pub fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
164-
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a]))
164+
map_to_vec(self, |&x| x)
165165
}
166166

167167
#[inline(always)]

0 commit comments

Comments
 (0)