diff --git a/components/util/smallvec.rs b/components/util/smallvec.rs index 5185c4ee521..00c43b76b9e 100644 --- a/components/util/smallvec.rs +++ b/components/util/smallvec.rs @@ -12,7 +12,6 @@ use std::kinds::marker::ContravariantLifetime; use std::mem; use std::ptr; use std::raw::Slice; -use rustrt::local_heap; use alloc::heap; // Generic code for all small vectors @@ -60,6 +59,7 @@ pub trait SmallVecPrivate { pub trait SmallVec : SmallVecPrivate where T: 'static { fn inline_size(&self) -> uint; fn len(&self) -> uint; + fn is_empty(&self) -> bool; fn cap(&self) -> uint; fn spilled(&self) -> bool { @@ -110,12 +110,13 @@ pub trait SmallVec : SmallVecPrivate where T: 'static { } else { None }; + let cap = self.cap(); let inline_size = self.inline_size(); self.set_cap(inline_size); self.set_len(0); SmallVecMoveIterator { allocation: ptr_opt, - cap: inline_size, + cap: cap, iter: iter, lifetime: ContravariantLifetime::<'a>, } @@ -169,13 +170,9 @@ pub trait SmallVec : SmallVecPrivate where T: 'static { ptr::copy_nonoverlapping_memory(new_alloc, self.begin(), self.len()); if self.spilled() { - if intrinsics::owns_managed::() { - local_heap::local_free(self.ptr() as *mut u8) - } else { - heap::deallocate(self.mut_ptr() as *mut u8, - mem::size_of::() * self.cap(), - mem::min_align_of::()) - } + heap::deallocate(self.mut_ptr() as *mut u8, + mem::size_of::() * self.cap(), + mem::min_align_of::()) } else { let mut_begin: *mut T = mem::transmute(self.begin()); intrinsics::set_memory(mut_begin, 0, self.len()) @@ -326,13 +323,9 @@ impl<'a, T: 'static> Drop for SmallVecMoveIterator<'a,T> { None => {} Some(allocation) => { unsafe { - if intrinsics::owns_managed::() { - local_heap::local_free(allocation as *mut u8) - } else { - heap::deallocate(allocation as *mut u8, - mem::size_of::() * self.cap, - mem::min_align_of::()) - } + heap::deallocate(allocation as *mut u8, + mem::size_of::() * self.cap, + mem::min_align_of::()) } } } @@ -383,6 +376,9 @@ macro_rules! def_small_vector( fn len(&self) -> uint { self.len } + fn is_empty(&self) -> bool { + self.len == 0 + } fn cap(&self) -> uint { self.cap } @@ -405,6 +401,26 @@ macro_rules! def_small_vector( } } + impl FromIterator for $name { + fn from_iter>(mut iter: I) -> $name { + let mut v = $name::new(); + + for elem in iter { + v.push(elem); + } + + v + } + } + + impl Extendable for $name { + fn extend>(&mut self, mut iter: I) { + for elem in iter { + self.push(elem); + } + } + } + impl $name { #[inline] pub fn new() -> $name { @@ -444,13 +460,9 @@ macro_rules! def_small_vector_drop_impl( *ptr.offset(i as int) = mem::uninitialized(); } - if intrinsics::owns_managed::() { - local_heap::local_free(self.ptr() as *mut u8) - } else { - heap::deallocate(self.mut_ptr() as *mut u8, - mem::size_of::() * self.cap(), - mem::min_align_of::()) - } + heap::deallocate(self.mut_ptr() as *mut u8, + mem::size_of::() * self.cap(), + mem::min_align_of::()) } } } @@ -527,4 +539,3 @@ pub mod tests { ].as_slice()); } } -