diff options
| author | bors <bors@rust-lang.org> | 2014-01-15 17:46:42 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-01-15 17:46:42 -0800 |
| commit | a5ed0c58cb9f38af940403c34e283b68c89f5aa2 (patch) | |
| tree | a8be28b83687b5a2fabc870c65a3a49b66b4bd95 /src/libstd/vec.rs | |
| parent | 36971217aa64b6fc5f543f2620e488d16e67b1f4 (diff) | |
| parent | 29840addd46b6ae01b61ee93247164d5818f09e0 (diff) | |
| download | rust-a5ed0c58cb9f38af940403c34e283b68c89f5aa2.tar.gz rust-a5ed0c58cb9f38af940403c34e283b68c89f5aa2.zip | |
auto merge of #11565 : mozilla/rust/snapshot, r=huonw
Diffstat (limited to 'src/libstd/vec.rs')
| -rw-r--r-- | src/libstd/vec.rs | 144 |
1 files changed, 0 insertions, 144 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 797582e57f4..20684bf4c49 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -116,18 +116,12 @@ use ptr::to_unsafe_ptr; use ptr; use ptr::RawPtr; use rt::global_heap::{malloc_raw, realloc_raw, exchange_free}; -#[cfg(stage0)] -use rt::local_heap::local_free; use mem; use mem::size_of; use uint; use unstable::finally::Finally; use unstable::intrinsics; -#[cfg(stage0)] -use unstable::intrinsics::{get_tydesc, owns_managed}; use unstable::raw::{Repr, Slice, Vec}; -#[cfg(stage0)] -use unstable::raw::Box; use util; /** @@ -182,30 +176,6 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] { /// Creates a new vector with a capacity of `capacity` #[inline] -#[cfg(stage0)] -pub fn with_capacity<T>(capacity: uint) -> ~[T] { - unsafe { - if owns_managed::<T>() { - let mut vec = ~[]; - vec.reserve(capacity); - vec - } else { - let alloc = capacity * mem::nonzero_size_of::<T>(); - let size = alloc + mem::size_of::<Vec<()>>(); - if alloc / mem::nonzero_size_of::<T>() != capacity || size < alloc { - fail!("vector size is too large: {}", capacity); - } - let ptr = malloc_raw(size) as *mut Vec<()>; - (*ptr).alloc = alloc; - (*ptr).fill = 0; - cast::transmute(ptr) - } - } -} - -/// Creates a new vector with a capacity of `capacity` -#[inline] -#[cfg(not(stage0))] pub fn with_capacity<T>(capacity: uint) -> ~[T] { unsafe { let alloc = capacity * mem::nonzero_size_of::<T>(); @@ -1503,31 +1473,6 @@ impl<T> OwnedVector<T> for ~[T] { self.move_iter().invert() } - #[cfg(stage0)] - fn reserve(&mut self, n: uint) { - // Only make the (slow) call into the runtime if we have to - if self.capacity() < n { - unsafe { - let td = get_tydesc::<T>(); - if owns_managed::<T>() { - let ptr: *mut *mut Box<Vec<()>> = cast::transmute(self); - ::at_vec::raw::reserve_raw(td, ptr, n); - } else { - let ptr: *mut *mut Vec<()> = cast::transmute(self); - let alloc = n * mem::nonzero_size_of::<T>(); - let size = alloc + mem::size_of::<Vec<()>>(); - if alloc / mem::nonzero_size_of::<T>() != n || size < alloc { - fail!("vector size is too large: {}", n); - } - *ptr = realloc_raw(*ptr as *mut c_void, size) - as *mut Vec<()>; - (**ptr).alloc = alloc; - } - } - } - } - - #[cfg(not(stage0))] fn reserve(&mut self, n: uint) { // Only make the (slow) call into the runtime if we have to if self.capacity() < n { @@ -1561,21 +1506,6 @@ impl<T> OwnedVector<T> for ~[T] { } #[inline] - #[cfg(stage0)] - fn capacity(&self) -> uint { - unsafe { - if owns_managed::<T>() { - let repr: **Box<Vec<()>> = cast::transmute(self); - (**repr).data.alloc / mem::nonzero_size_of::<T>() - } else { - let repr: **Vec<()> = cast::transmute(self); - (**repr).alloc / mem::nonzero_size_of::<T>() - } - } - } - - #[inline] - #[cfg(not(stage0))] fn capacity(&self) -> uint { unsafe { let repr: **Vec<()> = cast::transmute(self); @@ -1594,51 +1524,6 @@ impl<T> OwnedVector<T> for ~[T] { } #[inline] - #[cfg(stage0)] - fn push(&mut self, t: T) { - unsafe { - if owns_managed::<T>() { - let repr: **Box<Vec<()>> = cast::transmute(&mut *self); - let fill = (**repr).data.fill; - if (**repr).data.alloc <= fill { - self.reserve_additional(1); - } - - push_fast(self, t); - } else { - let repr: **Vec<()> = cast::transmute(&mut *self); - let fill = (**repr).fill; - if (**repr).alloc <= fill { - self.reserve_additional(1); - } - - push_fast(self, t); - } - } - - // This doesn't bother to make sure we have space. - #[inline] // really pretty please - unsafe fn push_fast<T>(this: &mut ~[T], t: T) { - if owns_managed::<T>() { - let repr: **mut Box<Vec<u8>> = cast::transmute(this); - let fill = (**repr).data.fill; - (**repr).data.fill += mem::nonzero_size_of::<T>(); - let p = to_unsafe_ptr(&((**repr).data.data)); - let p = ptr::offset(p, fill as int) as *mut T; - intrinsics::move_val_init(&mut(*p), t); - } else { - let repr: **mut Vec<u8> = cast::transmute(this); - let fill = (**repr).fill; - (**repr).fill += mem::nonzero_size_of::<T>(); - let p = to_unsafe_ptr(&((**repr).data)); - let p = ptr::offset(p, fill as int) as *mut T; - intrinsics::move_val_init(&mut(*p), t); - } - } - } - - #[inline] - #[cfg(not(stage0))] fn push(&mut self, t: T) { unsafe { let repr: **Vec<()> = cast::transmute(&mut *self); @@ -1821,20 +1706,8 @@ impl<T> OwnedVector<T> for ~[T] { i += 1u; } } - #[inline] - #[cfg(stage0)] - unsafe fn set_len(&mut self, new_len: uint) { - if owns_managed::<T>() { - let repr: **mut Box<Vec<()>> = cast::transmute(self); - (**repr).data.fill = new_len * mem::nonzero_size_of::<T>(); - } else { - let repr: **mut Vec<()> = cast::transmute(self); - (**repr).fill = new_len * mem::nonzero_size_of::<T>(); - } - } #[inline] - #[cfg(not(stage0))] unsafe fn set_len(&mut self, new_len: uint) { let repr: **mut Vec<()> = cast::transmute(self); (**repr).fill = new_len * mem::nonzero_size_of::<T>(); @@ -3010,23 +2883,6 @@ impl<T> DoubleEndedIterator<T> for MoveIterator<T> { } #[unsafe_destructor] -#[cfg(stage0)] -impl<T> Drop for MoveIterator<T> { - fn drop(&mut self) { - // destroy the remaining elements - for _x in *self {} - unsafe { - if owns_managed::<T>() { - local_free(self.allocation as *u8 as *c_char) - } else { - exchange_free(self.allocation as *u8 as *c_char) - } - } - } -} - -#[unsafe_destructor] -#[cfg(not(stage0))] impl<T> Drop for MoveIterator<T> { fn drop(&mut self) { // destroy the remaining elements |
