@@ -411,6 +411,13 @@ unsafe fn alloc_or_realloc<T>(ptr: *mut T, size: uint, old_size: uint) -> *mut T
411
411
}
412
412
}
413
413
414
+ #[ inline]
415
+ unsafe fn dealloc < T > ( ptr : * mut T , len : uint ) {
416
+ if size_of :: < T > ( ) != 0 {
417
+ deallocate ( ptr as * mut u8 , len * size_of :: < T > ( ) , min_align_of :: < T > ( ) )
418
+ }
419
+ }
420
+
414
421
impl < T > Vec < T > {
415
422
/// Returns the number of elements the vector can hold without
416
423
/// reallocating.
@@ -510,7 +517,7 @@ impl<T> Vec<T> {
510
517
if self . len == 0 {
511
518
if self . cap != 0 {
512
519
unsafe {
513
- deallocate ( self . ptr as * mut u8 , self . cap * size_of :: < T > ( ) , min_align_of :: < T > ( ) )
520
+ dealloc ( self . ptr , self . cap )
514
521
}
515
522
self . cap = 0 ;
516
523
}
@@ -658,7 +665,7 @@ impl<T> Vec<T> {
658
665
pub fn move_iter ( self ) -> MoveItems < T > {
659
666
unsafe {
660
667
let iter = transmute ( self . as_slice ( ) . iter ( ) ) ;
661
- let ptr = self . ptr as * mut u8 ;
668
+ let ptr = self . ptr ;
662
669
let cap = self . cap ;
663
670
forget ( self ) ;
664
671
MoveItems { allocation : ptr, cap : cap, iter : iter }
@@ -1412,9 +1419,7 @@ impl<T> Drop for Vec<T> {
1412
1419
for x in self . as_mut_slice ( ) . iter ( ) {
1413
1420
ptr:: read ( x) ;
1414
1421
}
1415
- if size_of :: < T > ( ) != 0 {
1416
- deallocate ( self . ptr as * mut u8 , self . cap * size_of :: < T > ( ) , min_align_of :: < T > ( ) )
1417
- }
1422
+ dealloc ( self . ptr , self . cap )
1418
1423
}
1419
1424
}
1420
1425
}
@@ -1434,7 +1439,7 @@ impl<T:fmt::Show> fmt::Show for Vec<T> {
1434
1439
1435
1440
/// An iterator that moves out of a vector.
1436
1441
pub struct MoveItems < T > {
1437
- allocation : * mut u8 , // the block of memory allocated for the vector
1442
+ allocation : * mut T , // the block of memory allocated for the vector
1438
1443
cap : uint , // the capacity of the vector
1439
1444
iter : Items < ' static , T >
1440
1445
}
@@ -1469,9 +1474,7 @@ impl<T> Drop for MoveItems<T> {
1469
1474
if self . cap != 0 {
1470
1475
for _x in * self { }
1471
1476
unsafe {
1472
- if size_of :: < T > ( ) != 0 {
1473
- deallocate ( self . allocation , self . cap * size_of :: < T > ( ) , min_align_of :: < T > ( ) )
1474
- }
1477
+ dealloc ( self . allocation , self . cap ) ;
1475
1478
}
1476
1479
}
1477
1480
}
0 commit comments