3
3
4
4
use core:: alloc:: LayoutError ;
5
5
use core:: cmp;
6
- use core:: intrinsics;
7
- use core:: mem:: { self , ManuallyDrop , MaybeUninit } ;
6
+ use core:: intrinsics:: { self , min_align_of as align_of , size_of } ;
7
+ use core:: mem:: { ManuallyDrop , MaybeUninit } ;
8
8
use core:: ops:: Drop ;
9
9
use core:: ptr:: { self , NonNull , Unique } ;
10
10
use core:: slice;
@@ -171,7 +171,7 @@ impl<T, A: Allocator> RawVec<T, A> {
171
171
}
172
172
173
173
fn allocate_in ( capacity : usize , init : AllocInit , alloc : A ) -> Self {
174
- if mem :: size_of :: < T > ( ) == 0 {
174
+ if size_of :: < T > ( ) == 0 {
175
175
Self :: new_in ( alloc)
176
176
} else {
177
177
// We avoid `unwrap_or_else` here because it bloats the amount of
@@ -228,7 +228,7 @@ impl<T, A: Allocator> RawVec<T, A> {
228
228
/// This will always be `usize::MAX` if `T` is zero-sized.
229
229
#[ inline( always) ]
230
230
pub fn capacity ( & self ) -> usize {
231
- if mem :: size_of :: < T > ( ) == 0 { usize:: MAX } else { self . cap }
231
+ if size_of :: < T > ( ) == 0 { usize:: MAX } else { self . cap }
232
232
}
233
233
234
234
/// Returns a shared reference to the allocator backing this `RawVec`.
@@ -237,14 +237,14 @@ impl<T, A: Allocator> RawVec<T, A> {
237
237
}
238
238
239
239
fn current_memory ( & self ) -> Option < ( NonNull < u8 > , Layout ) > {
240
- if mem :: size_of :: < T > ( ) == 0 || self . cap == 0 {
240
+ if size_of :: < T > ( ) == 0 || self . cap == 0 {
241
241
None
242
242
} else {
243
243
// We have an allocated chunk of memory, so we can bypass runtime
244
244
// checks to get our current layout.
245
245
unsafe {
246
- let align = mem :: align_of :: < T > ( ) ;
247
- let size = mem :: size_of :: < T > ( ) * self . cap ;
246
+ let align = align_of :: < T > ( ) ;
247
+ let size = size_of :: < T > ( ) * self . cap ;
248
248
let layout = Layout :: from_size_align_unchecked ( size, align) ;
249
249
Some ( ( self . ptr . cast ( ) . into ( ) , layout) )
250
250
}
@@ -367,8 +367,8 @@ impl<T, A: Allocator> RawVec<T, A> {
367
367
}
368
368
369
369
fn capacity_from_bytes ( excess : usize ) -> usize {
370
- debug_assert_ne ! ( mem :: size_of:: <T >( ) , 0 ) ;
371
- excess / mem :: size_of :: < T > ( )
370
+ debug_assert_ne ! ( size_of:: <T >( ) , 0 ) ;
371
+ excess / size_of :: < T > ( )
372
372
}
373
373
374
374
fn set_ptr ( & mut self , ptr : NonNull < [ u8 ] > ) {
@@ -387,7 +387,7 @@ impl<T, A: Allocator> RawVec<T, A> {
387
387
// This is ensured by the calling contexts.
388
388
debug_assert ! ( additional > 0 ) ;
389
389
390
- if mem :: size_of :: < T > ( ) == 0 {
390
+ if size_of :: < T > ( ) == 0 {
391
391
// Since we return a capacity of `usize::MAX` when `elem_size` is
392
392
// 0, getting to here necessarily means the `RawVec` is overfull.
393
393
return Err ( CapacityOverflow ) ;
@@ -406,7 +406,7 @@ impl<T, A: Allocator> RawVec<T, A> {
406
406
// - 4 if elements are moderate-sized (<= 1 KiB).
407
407
// - 1 otherwise, to avoid wasting too much space for very short Vecs.
408
408
// Note that `min_non_zero_cap` is computed statically.
409
- let elem_size = mem :: size_of :: < T > ( ) ;
409
+ let elem_size = size_of :: < T > ( ) ;
410
410
let min_non_zero_cap = if elem_size == 1 {
411
411
8
412
412
} else if elem_size <= 1024 {
@@ -428,7 +428,7 @@ impl<T, A: Allocator> RawVec<T, A> {
428
428
// `grow_amortized`, but this method is usually instantiated less often so
429
429
// it's less critical.
430
430
fn grow_exact ( & mut self , len : usize , additional : usize ) -> Result < ( ) , TryReserveError > {
431
- if mem :: size_of :: < T > ( ) == 0 {
431
+ if size_of :: < T > ( ) == 0 {
432
432
// Since we return a capacity of `usize::MAX` when the type size is
433
433
// 0, getting to here necessarily means the `RawVec` is overfull.
434
434
return Err ( CapacityOverflow ) ;
@@ -447,7 +447,7 @@ impl<T, A: Allocator> RawVec<T, A> {
447
447
assert ! ( amount <= self . capacity( ) , "Tried to shrink to a larger capacity" ) ;
448
448
449
449
let ( ptr, layout) = if let Some ( mem) = self . current_memory ( ) { mem } else { return Ok ( ( ) ) } ;
450
- let new_size = amount * mem :: size_of :: < T > ( ) ;
450
+ let new_size = amount * size_of :: < T > ( ) ;
451
451
452
452
let ptr = unsafe {
453
453
let new_layout = Layout :: from_size_align_unchecked ( new_size, layout. align ( ) ) ;
0 commit comments