Skip to content

Commit a26d9db

Browse files
committed
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.
1 parent d57aaae commit a26d9db

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)