@@ -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 , * } ,
@@ -278,39 +278,12 @@ impl<T, A: AllocRef> RawVec<T, A> {
278
278
needed_extra_capacity : usize ,
279
279
) -> Result < ( ) , TryReserveError > {
280
280
if self . needs_to_grow ( used_capacity, needed_extra_capacity) {
281
- self . grow_amortized ( used_capacity, needed_extra_capacity, MayMove )
281
+ self . grow_amortized ( used_capacity, needed_extra_capacity)
282
282
} else {
283
283
Ok ( ( ) )
284
284
}
285
285
}
286
286
287
- /// Attempts to ensure that the buffer contains at least enough space to hold
288
- /// `used_capacity + needed_extra_capacity` elements. If it doesn't already have
289
- /// enough capacity, will reallocate in place enough space plus comfortable slack
290
- /// space to get amortized `O(1)` behavior. Will limit this behaviour
291
- /// if it would needlessly cause itself to panic.
292
- ///
293
- /// If `used_capacity` exceeds `self.capacity()`, this may fail to actually allocate
294
- /// the requested space. This is not really unsafe, but the unsafe
295
- /// code *you* write that relies on the behavior of this function may break.
296
- ///
297
- /// Returns `true` if the reallocation attempt has succeeded.
298
- ///
299
- /// # Panics
300
- ///
301
- /// * Panics if the requested capacity exceeds `usize::MAX` bytes.
302
- /// * Panics on 32-bit platforms if the requested capacity exceeds
303
- /// `isize::MAX` bytes.
304
- pub fn reserve_in_place ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) -> bool {
305
- // This is more readable than putting this in one line:
306
- // `!self.needs_to_grow(...) || self.grow(...).is_ok()`
307
- if self . needs_to_grow ( used_capacity, needed_extra_capacity) {
308
- self . grow_amortized ( used_capacity, needed_extra_capacity, InPlace ) . is_ok ( )
309
- } else {
310
- true
311
- }
312
- }
313
-
314
287
/// Ensures that the buffer contains at least enough space to hold
315
288
/// `used_capacity + needed_extra_capacity` elements. If it doesn't already,
316
289
/// will reallocate the minimum possible amount of memory necessary.
@@ -399,11 +372,9 @@ impl<T, A: AllocRef> RawVec<T, A> {
399
372
& mut self ,
400
373
used_capacity : usize ,
401
374
needed_extra_capacity : usize ,
402
- placement : ReallocPlacement ,
403
375
) -> Result < ( ) , TryReserveError > {
404
376
// This is ensured by the calling contexts.
405
377
debug_assert ! ( needed_extra_capacity > 0 ) ;
406
-
407
378
if mem:: size_of :: < T > ( ) == 0 {
408
379
// Since we return a capacity of `usize::MAX` when `elem_size` is
409
380
// 0, getting to here necessarily means the `RawVec` is overfull.
@@ -437,7 +408,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
437
408
let new_layout = Layout :: array :: < T > ( cap) ;
438
409
439
410
// `finish_grow` is non-generic over `T`.
440
- let memory = finish_grow ( new_layout, placement , self . current_memory ( ) , & mut self . alloc ) ?;
411
+ let memory = finish_grow ( new_layout, self . current_memory ( ) , & mut self . alloc ) ?;
441
412
self . set_memory ( memory) ;
442
413
Ok ( ( ) )
443
414
}
@@ -460,7 +431,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
460
431
let new_layout = Layout :: array :: < T > ( cap) ;
461
432
462
433
// `finish_grow` is non-generic over `T`.
463
- let memory = finish_grow ( new_layout, MayMove , self . current_memory ( ) , & mut self . alloc ) ?;
434
+ let memory = finish_grow ( new_layout, self . current_memory ( ) , & mut self . alloc ) ?;
464
435
self . set_memory ( memory) ;
465
436
Ok ( ( ) )
466
437
}
@@ -494,7 +465,6 @@ impl<T, A: AllocRef> RawVec<T, A> {
494
465
// much smaller than the number of `T` types.)
495
466
fn finish_grow < A > (
496
467
new_layout : Result < Layout , LayoutErr > ,
497
- placement : ReallocPlacement ,
498
468
current_memory : Option < ( NonNull < u8 > , Layout ) > ,
499
469
alloc : & mut A ,
500
470
) -> Result < MemoryBlock , TryReserveError >
@@ -508,12 +478,9 @@ where
508
478
509
479
let memory = if let Some ( ( ptr, old_layout) ) = current_memory {
510
480
debug_assert_eq ! ( old_layout. align( ) , new_layout. align( ) ) ;
511
- unsafe { alloc. grow ( ptr, old_layout, new_layout. size ( ) , placement , Uninitialized ) }
481
+ unsafe { alloc. grow ( ptr, old_layout, new_layout. size ( ) , MayMove , Uninitialized ) }
512
482
} else {
513
- match placement {
514
- MayMove => alloc. alloc ( new_layout, Uninitialized ) ,
515
- InPlace => Err ( AllocErr ) ,
516
- }
483
+ alloc. alloc ( new_layout, Uninitialized )
517
484
}
518
485
. map_err ( |_| AllocError { layout : new_layout, non_exhaustive : ( ) } ) ?;
519
486
0 commit comments