diff options
| author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2013-04-12 19:21:46 +0200 |
|---|---|---|
| committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2013-04-13 14:29:14 +0200 |
| commit | a26d9db95f2ff13030bb4a7fdd380165bf8abfc1 (patch) | |
| tree | 51ce7de0a5bcf279b9e6b0954d81eb6d9abe04a4 | |
| parent | d57aaae02525f6e3c7a051fed94966dbbad5e7cf (diff) | |
| download | rust-a26d9db95f2ff13030bb4a7fdd380165bf8abfc1.tar.gz rust-a26d9db95f2ff13030bb4a7fdd380165bf8abfc1.zip | |
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.
| -rw-r--r-- | src/libcore/iter.rs | 2 |
1 files changed, 1 insertions, 1 deletions
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<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)] |
