mirror of
https://github.com/servo/servo.git
synced 2025-06-25 09:34:32 +01:00
util: Add some utility methods to SmallVec
.
This commit is contained in:
parent
1b04165f67
commit
dae4166eb3
1 changed files with 28 additions and 0 deletions
|
@ -60,6 +60,12 @@ pub trait SmallVec<T> : SmallVecPrivate<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
/// NB: For efficiency reasons (avoiding making a second copy of the inline elements), this
|
||||||
/// actually clears out the original array instead of moving it.
|
/// actually clears out the original array instead of moving it.
|
||||||
fn move_iter<'a>(&'a mut self) -> SmallVecMoveIterator<'a,T> {
|
fn move_iter<'a>(&'a mut self) -> SmallVecMoveIterator<'a,T> {
|
||||||
|
@ -94,6 +100,12 @@ pub trait SmallVec<T> : SmallVecPrivate<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn push_all_move<V:SmallVec<T>>(&mut self, mut other: V) {
|
||||||
|
for value in other.move_iter() {
|
||||||
|
self.push(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn grow(&mut self, new_cap: uint) {
|
fn grow(&mut self, new_cap: uint) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let new_alloc: *mut T = cast::transmute(global_heap::malloc_raw(mem::size_of::<T>() *
|
let new_alloc: *mut T = cast::transmute(global_heap::malloc_raw(mem::size_of::<T>() *
|
||||||
|
@ -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> {
|
pub struct SmallVecMoveIterator<'a,T> {
|
||||||
priv allocation: Option<*mut u8>,
|
priv allocation: Option<*mut u8>,
|
||||||
priv iter: SmallVecIterator<'static,T>,
|
priv iter: SmallVecIterator<'static,T>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue