Skip to content

Commit 0621cca

Browse files
committed
vec: move some code inside alloc_or_realloc
1 parent f8e92cb commit 0621cca

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/libstd/vec.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ impl<T> Container for Vec<T> {
403403

404404
// FIXME: #13996: need a way to mark the return value as `noalias`
405405
#[inline(never)]
406-
unsafe fn alloc_or_realloc(ptr: *mut u8, size: uint, align: uint, old_size: uint) -> *mut u8 {
406+
unsafe fn alloc_or_realloc<T>(ptr: *mut T, size: uint, old_size: uint) -> *mut T {
407407
if old_size == 0 {
408-
allocate(size, align)
408+
allocate(size, min_align_of::<T>()) as *mut T
409409
} else {
410-
reallocate(ptr, size, align, old_size)
410+
reallocate(ptr as *mut u8, size, min_align_of::<T>(), old_size) as *mut T
411411
}
412412
}
413413

@@ -491,8 +491,7 @@ impl<T> Vec<T> {
491491
if capacity > self.cap {
492492
let size = capacity.checked_mul(&size_of::<T>()).expect("capacity overflow");
493493
unsafe {
494-
self.ptr = alloc_or_realloc(self.ptr as *mut u8, size, min_align_of::<T>(),
495-
self.cap * size_of::<T>()) as *mut T;
494+
self.ptr = alloc_or_realloc(self.ptr, size, self.cap * size_of::<T>());
496495
}
497496
self.cap = capacity;
498497
}
@@ -573,8 +572,7 @@ impl<T> Vec<T> {
573572
let size = max(old_size, 2 * size_of::<T>()) * 2;
574573
if old_size > size { fail!("capacity overflow") }
575574
unsafe {
576-
self.ptr = alloc_or_realloc(self.ptr as *mut u8, size, min_align_of::<T>(),
577-
self.cap * size_of::<T>()) as *mut u8 as *mut T;
575+
self.ptr = alloc_or_realloc(self.ptr, size, self.cap * size_of::<T>());
578576
}
579577
self.cap = max(self.cap, 2) * 2;
580578
}

0 commit comments

Comments
 (0)