Skip to content

Make the Vec data structure layout match raw::Slice. #18303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl<T> BoxedSlice<T> for Box<[T]> {
#[experimental]
fn into_vec(mut self) -> Vec<T> {
unsafe {
let xs = Vec::from_raw_parts(self.len(), self.len(), self.as_mut_ptr());
let xs = Vec::from_raw_parts(self.as_mut_ptr(), self.len(), self.len());
mem::forget(self);
xs
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ pub mod raw {
#[inline]
pub unsafe fn from_parts(buf: *mut u8, length: uint, capacity: uint) -> String {
String {
vec: Vec::from_raw_parts(length, capacity, buf),
vec: Vec::from_raw_parts(buf, length, capacity),
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ use slice::{Items, MutItems};
#[unsafe_no_drop_flag]
#[stable]
pub struct Vec<T> {
ptr: *mut T,
len: uint,
cap: uint,
ptr: *mut T
}

impl<T> Vec<T> {
Expand All @@ -125,7 +125,7 @@ impl<T> Vec<T> {
// non-null value which is fine since we never call deallocate on the ptr
// if cap is 0. The reason for this is because the pointer of a slice
// being NULL would break the null pointer optimization for enums.
Vec { len: 0, cap: 0, ptr: EMPTY as *mut T }
Vec { ptr: EMPTY as *mut T, len: 0, cap: 0 }
}

/// Constructs a new, empty `Vec` with the specified capacity.
Expand Down Expand Up @@ -159,14 +159,14 @@ impl<T> Vec<T> {
#[stable]
pub fn with_capacity(capacity: uint) -> Vec<T> {
if mem::size_of::<T>() == 0 {
Vec { len: 0, cap: uint::MAX, ptr: EMPTY as *mut T }
Vec { ptr: EMPTY as *mut T, len: 0, cap: uint::MAX }
} else if capacity == 0 {
Vec::new()
} else {
let size = capacity.checked_mul(&mem::size_of::<T>())
.expect("capacity overflow");
let ptr = unsafe { allocate(size, mem::min_align_of::<T>()) };
Vec { len: 0, cap: capacity, ptr: ptr as *mut T }
Vec { ptr: ptr as *mut T, len: 0, cap: capacity }
}
}

Expand Down Expand Up @@ -237,9 +237,9 @@ impl<T> Vec<T> {
/// }
/// ```
#[experimental]
pub unsafe fn from_raw_parts(length: uint, capacity: uint,
ptr: *mut T) -> Vec<T> {
Vec { len: length, cap: capacity, ptr: ptr }
pub unsafe fn from_raw_parts(ptr: *mut T, length: uint,
capacity: uint) -> Vec<T> {
Vec { ptr: ptr, len: length, cap: capacity }
}

/// Consumes the `Vec`, partitioning it based on a predicate.
Expand Down Expand Up @@ -1680,7 +1680,7 @@ impl<'a, T> Drop for DerefVec<'a, T> {
pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> {
unsafe {
DerefVec {
x: Vec::from_raw_parts(x.len(), x.len(), x.as_ptr() as *mut T),
x: Vec::from_raw_parts(x.as_ptr() as *mut T, x.len(), x.len()),
l: ContravariantLifetime::<'a>
}
}
Expand Down Expand Up @@ -1929,7 +1929,7 @@ impl<T> Vec<T> {
let vec_cap = pv.vec.capacity();
let vec_ptr = pv.vec.as_mut_ptr() as *mut U;
mem::forget(pv);
Vec::from_raw_parts(vec_len, vec_cap, vec_ptr)
Vec::from_raw_parts(vec_ptr, vec_len, vec_cap)
}
} else {
// Put the `Vec` into the `PartialVecZeroSized` structure and
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/owned_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<T> OwnedSlice<T> {
pub fn into_vec(self) -> Vec<T> {
// null is ok, because len == 0 in that case, as required by Vec.
unsafe {
let ret = Vec::from_raw_parts(self.len, self.len, self.data);
let ret = Vec::from_raw_parts(self.data, self.len, self.len);
// the vector owns the allocation now
mem::forget(self);
ret
Expand Down