From a26d9db95f2ff13030bb4a7fdd380165bf8abfc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Fri, 12 Apr 2013 19:21:46 +0200 Subject: [PATCH] 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. --- src/libcore/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 9c704fbd699..a220cd520c3 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -161,7 +161,7 @@ pub fn foldl>(self: &IA, b0: B, blk: &fn(&B, &A) -> B) #[inline(always)] pub fn to_vec>(self: &IA) -> ~[A] { - foldl::(self, ~[], |r, a| vec::append(copy (*r), ~[*a])) + map_to_vec(self, |&x| x) } #[inline(always)]