@@ -9,7 +9,7 @@ use core::ptr::{NonNull, Unique};
9
9
use core:: slice;
10
10
11
11
use crate :: alloc:: {
12
- handle_alloc_error, AllocErr ,
12
+ handle_alloc_error,
13
13
AllocInit :: { self , * } ,
14
14
AllocRef , Global , Layout ,
15
15
ReallocPlacement :: { self , * } ,
@@ -302,39 +302,12 @@ impl<T, A: AllocRef> RawVec<T, A> {
302
302
needed_extra_capacity : usize ,
303
303
) -> Result < ( ) , TryReserveError > {
304
304
if self . needs_to_grow ( used_capacity, needed_extra_capacity) {
305
- self . grow_amortized ( used_capacity, needed_extra_capacity, MayMove )
305
+ self . grow_amortized ( used_capacity, needed_extra_capacity)
306
306
} else {
307
307
Ok ( ( ) )
308
308
}
309
309
}
310
310
311
- /// Attempts to ensure that the buffer contains at least enough space to hold
312
- /// `used_capacity + needed_extra_capacity` elements. If it doesn't already have
313
- /// enough capacity, will reallocate in place enough space plus comfortable slack
314
- /// space to get amortized `O(1)` behavior. Will limit this behaviour
315
- /// if it would needlessly cause itself to panic.
316
- ///
317
- /// If `used_capacity` exceeds `self.capacity()`, this may fail to actually allocate
318
- /// the requested space. This is not really unsafe, but the unsafe
319
- /// code *you* write that relies on the behavior of this function may break.
320
- ///
321
- /// Returns `true` if the reallocation attempt has succeeded.
322
- ///
323
- /// # Panics
324
- ///
325
- /// * Panics if the requested capacity exceeds `usize::MAX` bytes.
326
- /// * Panics on 32-bit platforms if the requested capacity exceeds
327
- /// `isize::MAX` bytes.
328
- pub fn reserve_in_place ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) -> bool {
329
- // This is more readable than putting this in one line:
330
- // `!self.needs_to_grow(...) || self.grow(...).is_ok()`
331
- if self . needs_to_grow ( used_capacity, needed_extra_capacity) {
332
- self . grow_amortized ( used_capacity, needed_extra_capacity, InPlace ) . is_ok ( )
333
- } else {
334
- true
335
- }
336
- }
337
-
338
311
/// Ensures that the buffer contains at least enough space to hold
339
312
/// `used_capacity + needed_extra_capacity` elements. If it doesn't already,
340
313
/// will reallocate the minimum possible amount of memory necessary.
@@ -423,11 +396,9 @@ impl<T, A: AllocRef> RawVec<T, A> {
423
396
& mut self ,
424
397
used_capacity : usize ,
425
398
needed_extra_capacity : usize ,
426
- placement : ReallocPlacement ,
427
399
) -> Result < ( ) , TryReserveError > {
428
400
// This is ensured by the calling contexts.
429
401
debug_assert ! ( needed_extra_capacity > 0 ) ;
430
-
431
402
if mem:: size_of :: < T > ( ) == 0 {
432
403
// Since we return a capacity of `usize::MAX` when `elem_size` is
433
404
// 0, getting to here necessarily means the `RawVec` is overfull.
@@ -461,7 +432,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
461
432
let new_layout = Layout :: array :: < T > ( cap) ;
462
433
463
434
// `finish_grow` is non-generic over `T`.
464
- let memory = finish_grow ( new_layout, placement , self . current_memory ( ) , & mut self . alloc ) ?;
435
+ let memory = finish_grow ( new_layout, self . current_memory ( ) , & mut self . alloc ) ?;
465
436
self . set_memory ( memory) ;
466
437
Ok ( ( ) )
467
438
}
@@ -484,7 +455,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
484
455
let new_layout = Layout :: array :: < T > ( cap) ;
485
456
486
457
// `finish_grow` is non-generic over `T`.
487
- let memory = finish_grow ( new_layout, MayMove , self . current_memory ( ) , & mut self . alloc ) ?;
458
+ let memory = finish_grow ( new_layout, self . current_memory ( ) , & mut self . alloc ) ?;
488
459
self . set_memory ( memory) ;
489
460
Ok ( ( ) )
490
461
}
@@ -518,7 +489,6 @@ impl<T, A: AllocRef> RawVec<T, A> {
518
489
// much smaller than the number of `T` types.)
519
490
fn finish_grow < A > (
520
491
new_layout : Result < Layout , LayoutErr > ,
521
- placement : ReallocPlacement ,
522
492
current_memory : Option < ( NonNull < u8 > , Layout ) > ,
523
493
alloc : & mut A ,
524
494
) -> Result < MemoryBlock , TryReserveError >
@@ -532,12 +502,9 @@ where
532
502
533
503
let memory = if let Some ( ( ptr, old_layout) ) = current_memory {
534
504
debug_assert_eq ! ( old_layout. align( ) , new_layout. align( ) ) ;
535
- unsafe { alloc. grow ( ptr, old_layout, new_layout. size ( ) , placement , Uninitialized ) }
505
+ unsafe { alloc. grow ( ptr, old_layout, new_layout. size ( ) , MayMove , Uninitialized ) }
536
506
} else {
537
- match placement {
538
- MayMove => alloc. alloc ( new_layout, Uninitialized ) ,
539
- InPlace => Err ( AllocErr ) ,
540
- }
507
+ alloc. alloc ( new_layout, Uninitialized )
541
508
}
542
509
. map_err ( |_| AllocError { layout : new_layout, non_exhaustive : ( ) } ) ?;
543
510
0 commit comments