Skip to content

Commit 301d0af

Browse files
committed
Remove RawVec::reserve_in_place.
Also remove a now-unnecessary `placement` argument.
1 parent b789617 commit 301d0af

File tree

1 file changed

+6
-39
lines changed

1 file changed

+6
-39
lines changed

src/liballoc/raw_vec.rs

+6-39
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::ptr::{NonNull, Unique};
99
use core::slice;
1010

1111
use crate::alloc::{
12-
handle_alloc_error, AllocErr,
12+
handle_alloc_error,
1313
AllocInit::{self, *},
1414
AllocRef, Global, Layout,
1515
ReallocPlacement::{self, *},
@@ -278,39 +278,12 @@ impl<T, A: AllocRef> RawVec<T, A> {
278278
needed_extra_capacity: usize,
279279
) -> Result<(), TryReserveError> {
280280
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)
282282
} else {
283283
Ok(())
284284
}
285285
}
286286

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-
314287
/// Ensures that the buffer contains at least enough space to hold
315288
/// `used_capacity + needed_extra_capacity` elements. If it doesn't already,
316289
/// will reallocate the minimum possible amount of memory necessary.
@@ -399,11 +372,9 @@ impl<T, A: AllocRef> RawVec<T, A> {
399372
&mut self,
400373
used_capacity: usize,
401374
needed_extra_capacity: usize,
402-
placement: ReallocPlacement,
403375
) -> Result<(), TryReserveError> {
404376
// This is ensured by the calling contexts.
405377
debug_assert!(needed_extra_capacity > 0);
406-
407378
if mem::size_of::<T>() == 0 {
408379
// Since we return a capacity of `usize::MAX` when `elem_size` is
409380
// 0, getting to here necessarily means the `RawVec` is overfull.
@@ -437,7 +408,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
437408
let new_layout = Layout::array::<T>(cap);
438409

439410
// `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)?;
441412
self.set_memory(memory);
442413
Ok(())
443414
}
@@ -460,7 +431,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
460431
let new_layout = Layout::array::<T>(cap);
461432

462433
// `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)?;
464435
self.set_memory(memory);
465436
Ok(())
466437
}
@@ -494,7 +465,6 @@ impl<T, A: AllocRef> RawVec<T, A> {
494465
// much smaller than the number of `T` types.)
495466
fn finish_grow<A>(
496467
new_layout: Result<Layout, LayoutErr>,
497-
placement: ReallocPlacement,
498468
current_memory: Option<(NonNull<u8>, Layout)>,
499469
alloc: &mut A,
500470
) -> Result<MemoryBlock, TryReserveError>
@@ -508,12 +478,9 @@ where
508478

509479
let memory = if let Some((ptr, old_layout)) = current_memory {
510480
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) }
512482
} else {
513-
match placement {
514-
MayMove => alloc.alloc(new_layout, Uninitialized),
515-
InPlace => Err(AllocErr),
516-
}
483+
alloc.alloc(new_layout, Uninitialized)
517484
}
518485
.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })?;
519486

0 commit comments

Comments
 (0)