Skip to content

Commit 87a5f0d

Browse files
author
Clark Gaebel
committed
Make the Vec data structure layout match raw::Slice.
Fixes #18302 r? @thestinger
1 parent a10917a commit 87a5f0d

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/libcollections/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<T> BoxedSlice<T> for Box<[T]> {
292292
#[experimental]
293293
fn into_vec(mut self) -> Vec<T> {
294294
unsafe {
295-
let xs = Vec::from_raw_parts(self.len(), self.len(), self.as_mut_ptr());
295+
let xs = Vec::from_raw_parts(self.as_mut_ptr(), self.len(), self.len());
296296
mem::forget(self);
297297
xs
298298
}

src/libcollections/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ pub mod raw {
780780
#[inline]
781781
pub unsafe fn from_parts(buf: *mut u8, length: uint, capacity: uint) -> String {
782782
String {
783-
vec: Vec::from_raw_parts(length, capacity, buf),
783+
vec: Vec::from_raw_parts(buf, length, capacity),
784784
}
785785
}
786786

src/libcollections/vec.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ use slice::{Items, MutItems};
103103
#[unsafe_no_drop_flag]
104104
#[stable]
105105
pub struct Vec<T> {
106+
ptr: *mut T,
106107
len: uint,
107108
cap: uint,
108-
ptr: *mut T
109109
}
110110

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

131131
/// Constructs a new, empty `Vec` with the specified capacity.
@@ -159,14 +159,14 @@ impl<T> Vec<T> {
159159
#[stable]
160160
pub fn with_capacity(capacity: uint) -> Vec<T> {
161161
if mem::size_of::<T>() == 0 {
162-
Vec { len: 0, cap: uint::MAX, ptr: EMPTY as *mut T }
162+
Vec { ptr: EMPTY as *mut T, len: 0, cap: uint::MAX }
163163
} else if capacity == 0 {
164164
Vec::new()
165165
} else {
166166
let size = capacity.checked_mul(&mem::size_of::<T>())
167167
.expect("capacity overflow");
168168
let ptr = unsafe { allocate(size, mem::min_align_of::<T>()) };
169-
Vec { len: 0, cap: capacity, ptr: ptr as *mut T }
169+
Vec { ptr: ptr as *mut T, len: 0, cap: capacity }
170170
}
171171
}
172172

@@ -237,9 +237,9 @@ impl<T> Vec<T> {
237237
/// }
238238
/// ```
239239
#[experimental]
240-
pub unsafe fn from_raw_parts(length: uint, capacity: uint,
241-
ptr: *mut T) -> Vec<T> {
242-
Vec { len: length, cap: capacity, ptr: ptr }
240+
pub unsafe fn from_raw_parts(ptr: *mut T, length: uint,
241+
capacity: uint) -> Vec<T> {
242+
Vec { ptr: ptr, len: length, cap: capacity }
243243
}
244244

245245
/// Consumes the `Vec`, partitioning it based on a predicate.
@@ -1680,7 +1680,7 @@ impl<'a, T> Drop for DerefVec<'a, T> {
16801680
pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> {
16811681
unsafe {
16821682
DerefVec {
1683-
x: Vec::from_raw_parts(x.len(), x.len(), x.as_ptr() as *mut T),
1683+
x: Vec::from_raw_parts(x.as_ptr() as *mut T, x.len(), x.len()),
16841684
l: ContravariantLifetime::<'a>
16851685
}
16861686
}
@@ -1929,7 +1929,7 @@ impl<T> Vec<T> {
19291929
let vec_cap = pv.vec.capacity();
19301930
let vec_ptr = pv.vec.as_mut_ptr() as *mut U;
19311931
mem::forget(pv);
1932-
Vec::from_raw_parts(vec_len, vec_cap, vec_ptr)
1932+
Vec::from_raw_parts(vec_ptr, vec_len, vec_cap)
19331933
}
19341934
} else {
19351935
// Put the `Vec` into the `PartialVecZeroSized` structure and

src/libsyntax/owned_slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<T> OwnedSlice<T> {
7474
pub fn into_vec(self) -> Vec<T> {
7575
// null is ok, because len == 0 in that case, as required by Vec.
7676
unsafe {
77-
let ret = Vec::from_raw_parts(self.len, self.len, self.data);
77+
let ret = Vec::from_raw_parts(self.data, self.len, self.len);
7878
// the vector owns the allocation now
7979
mem::forget(self);
8080
ret

0 commit comments

Comments
 (0)