diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-09-14 19:09:38 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-09-14 19:09:38 -0700 |
| commit | aa2ab2659f6c7aca79ddaaac5370da8aea6a18d6 (patch) | |
| tree | 084c63998f0d1552b9db812bfeded7a0e451dac3 /src/libcore/vec.rs | |
| parent | 1c5db46f8e44441ba1aa11f0f607b7c015fd1fa5 (diff) | |
Add core::reflect, start migrating core::repr to use it. Tidy up various Repr types.
Diffstat (limited to 'src/libcore/vec.rs')
| -rw-r--r-- | src/libcore/vec.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 22dfa12fae6..2f84a30a49b 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -169,7 +169,7 @@ fn reserve_at_least<T>(&v: ~[const T], n: uint) { pure fn capacity<T>(&&v: ~[const T]) -> uint { unsafe { let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - (**repr).alloc / sys::size_of::<T>() + (**repr).unboxed.alloc / sys::size_of::<T>() } } @@ -565,8 +565,8 @@ fn swap_remove<T>(&v: ~[const T], index: uint) -> T { fn push<T>(&v: ~[const T], +initval: T) { unsafe { let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - let fill = (**repr).fill; - if (**repr).alloc > fill { + let fill = (**repr).unboxed.fill; + if (**repr).unboxed.alloc > fill { push_fast(v, move initval); } else { @@ -579,9 +579,9 @@ fn push<T>(&v: ~[const T], +initval: T) { #[inline(always)] // really pretty please unsafe fn push_fast<T>(&v: ~[const T], +initval: T) { let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - let fill = (**repr).fill; - (**repr).fill += sys::size_of::<T>(); - let p = ptr::addr_of((**repr).data); + let fill = (**repr).unboxed.fill; + (**repr).unboxed.fill += sys::size_of::<T>(); + let p = ptr::addr_of((**repr).unboxed.data); let p = ptr::offset(p, fill) as *mut T; rusti::move_val_init(*p, move initval); } @@ -1787,13 +1787,19 @@ impl<T: Copy> &[T]: ImmutableCopyableVector<T> { /// Unsafe operations mod raw { // FIXME: This should have crate visibility (#1893 blocks that) - /// The internal representation of a vector - type VecRepr = { - box_header: (uint, uint, uint, uint), + + /// The internal representation of a (boxed) vector + struct VecRepr { + box_header: box::raw::BoxHeaderRepr, + unboxed: UnboxedVecRepr + } + + /// The internal 'unboxed' representation of a vector + struct UnboxedVecRepr { mut fill: uint, mut alloc: uint, data: u8 - }; + } type SliceRepr = { mut data: *u8, @@ -1827,7 +1833,7 @@ mod raw { #[inline(always)] unsafe fn set_len<T>(&&v: ~[const T], new_len: uint) { let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - (**repr).fill = new_len * sys::size_of::<T>(); + (**repr).unboxed.fill = new_len * sys::size_of::<T>(); } /** |
