diff --git a/src/components/util/smallvec.rs b/src/components/util/smallvec.rs index ab51fd961f1..614d211ea3a 100644 --- a/src/components/util/smallvec.rs +++ b/src/components/util/smallvec.rs @@ -60,6 +60,12 @@ pub trait SmallVec : SmallVecPrivate { } } + fn mut_iter<'a>(&'a mut self) -> SmallVecMutIterator<'a,T> { + SmallVecMutIterator { + iter: self.iter(), + } + } + /// NB: For efficiency reasons (avoiding making a second copy of the inline elements), this /// actually clears out the original array instead of moving it. fn move_iter<'a>(&'a mut self) -> SmallVecMoveIterator<'a,T> { @@ -94,6 +100,12 @@ pub trait SmallVec : SmallVecPrivate { } } + fn push_all_move>(&mut self, mut other: V) { + for value in other.move_iter() { + self.push(value) + } + } + fn grow(&mut self, new_cap: uint) { unsafe { let new_alloc: *mut T = cast::transmute(global_heap::malloc_raw(mem::size_of::() * @@ -194,6 +206,22 @@ impl<'a,T> Iterator<&'a T> for SmallVecIterator<'a,T> { } } +pub struct SmallVecMutIterator<'a,T> { + priv iter: SmallVecIterator<'a,T>, +} + +impl<'a,T> Iterator<&'a mut T> for SmallVecMutIterator<'a,T> { + #[inline] + fn next(&mut self) -> Option<&'a mut T> { + unsafe { + match self.iter.next() { + None => None, + Some(reference) => Some(cast::transmute::<&'a T,&'a mut T>(reference)), + } + } + } +} + pub struct SmallVecMoveIterator<'a,T> { priv allocation: Option<*mut u8>, priv iter: SmallVecIterator<'static,T>,