about summary refs log tree commit diff
path: root/src/libsyntax/fold.rs
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2014-05-19 12:11:06 +0300
committerEduard Burtescu <edy.burt@gmail.com>2014-09-14 04:20:35 +0300
commitf8df4fadc86f44cb5f6e69f29634dcfa6701b070 (patch)
treeb256bdaeeef6909c39cf7af6ab70814991fc29bf /src/libsyntax/fold.rs
parent946bb4b10b3b758dbebf773a178cf99de1dd023c (diff)
downloadrust-f8df4fadc86f44cb5f6e69f29634dcfa6701b070.tar.gz
rust-f8df4fadc86f44cb5f6e69f29634dcfa6701b070.zip
syntax: implement in-place folding of P<T> and Vec<T>.
Diffstat (limited to 'src/libsyntax/fold.rs')
-rw-r--r--src/libsyntax/fold.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 44ed347d70c..e63954c3680 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -35,8 +35,15 @@ pub trait MoveMap<T> {
 }
 
 impl<T> MoveMap<T> for Vec<T> {
-    fn move_map(self, f: |T| -> T) -> Vec<T> {
-        self.move_iter().map(f).collect()
+    fn move_map(mut self, f: |T| -> T) -> Vec<T> {
+        use std::{mem, ptr};
+        for p in self.mut_iter() {
+            unsafe {
+                // FIXME(#5016) this shouldn't need to zero to be safe.
+                mem::move_val_init(p, f(ptr::read_and_zero(p)));
+            }
+        }
+        self
     }
 }