summary refs log tree commit diff
path: root/src/libsyntax/util
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2014-09-07 20:00:54 +0300
committerEduard Burtescu <edy.burt@gmail.com>2014-09-14 03:39:35 +0300
commit9259b022f8ec05072993fd5e3e9f2eba3afc0c95 (patch)
tree064e9af18cd39639574f22930c38f2a156a3f8be /src/libsyntax/util
parentcccb6f84a317d1f7d516e6bb2c898c946629ab1f (diff)
downloadrust-9259b022f8ec05072993fd5e3e9f2eba3afc0c95.tar.gz
rust-9259b022f8ec05072993fd5e3e9f2eba3afc0c95.zip
syntax: fold: use move semantics for efficient folding.
Diffstat (limited to 'src/libsyntax/util')
-rw-r--r--src/libsyntax/util/small_vector.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs
index 517c5e5bf47..47aef987a63 100644
--- a/src/libsyntax/util/small_vector.rs
+++ b/src/libsyntax/util/small_vector.rs
@@ -12,6 +12,8 @@ use std::mem;
 use std::slice;
 use std::vec;
 
+use fold::MoveMap;
+
 /// A vector type optimized for cases where the size is almost always 0 or 1
 pub struct SmallVector<T> {
     repr: SmallVectorRepr<T>,
@@ -20,7 +22,7 @@ pub struct SmallVector<T> {
 enum SmallVectorRepr<T> {
     Zero,
     One(T),
-    Many(Vec<T> ),
+    Many(Vec<T>),
 }
 
 impl<T> Collection for SmallVector<T> {
@@ -160,6 +162,17 @@ impl<T> Iterator<T> for MoveItems<T> {
     }
 }
 
+impl<T> MoveMap<T> for SmallVector<T> {
+    fn move_map(self, f: |T| -> T) -> SmallVector<T> {
+        let repr = match self.repr {
+            Zero => Zero,
+            One(v) => One(f(v)),
+            Many(vs) => Many(vs.move_map(f))
+        };
+        SmallVector { repr: repr }
+    }
+}
+
 #[cfg(test)]
 mod test {
     use super::*;