diff options
Diffstat (limited to 'src/libsyntax/util/small_vector.rs')
| -rw-r--r-- | src/libsyntax/util/small_vector.rs | 15 |
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::*; |
