Skip to content

Commit cb8bc8e

Browse files
committed
Remove RawVec::reserve_in_place.
Also remove a now-unnecessary `placement` argument.
1 parent 7145b87 commit cb8bc8e

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, *},
@@ -302,39 +302,12 @@ impl<T, A: AllocRef> RawVec<T, A> {
302302
needed_extra_capacity: usize,
303303
) -> Result<(), TryReserveError> {
304304
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)
306306
} else {
307307
Ok(())
308308
}
309309
}
310310

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-
338311
/// Ensures that the buffer contains at least enough space to hold
339312
/// `used_capacity + needed_extra_capacity` elements. If it doesn't already,
340313
/// will reallocate the minimum possible amount of memory necessary.
@@ -423,11 +396,9 @@ impl<T, A: AllocRef> RawVec<T, A> {
423396
&mut self,
424397
used_capacity: usize,
425398
needed_extra_capacity: usize,
426-
placement: ReallocPlacement,
427399
) -> Result<(), TryReserveError> {
428400
// This is ensured by the calling contexts.
429401
debug_assert!(needed_extra_capacity > 0);
430-
431402
if mem::size_of::<T>() == 0 {
432403
// Since we return a capacity of `usize::MAX` when `elem_size` is
433404
// 0, getting to here necessarily means the `RawVec` is overfull.
@@ -461,7 +432,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
461432
let new_layout = Layout::array::<T>(cap);
462433

463434
// `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)?;
465436
self.set_memory(memory);
466437
Ok(())
467438
}
@@ -484,7 +455,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
484455
let new_layout = Layout::array::<T>(cap);
485456

486457
// `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)?;
488459
self.set_memory(memory);
489460
Ok(())
490461
}
@@ -518,7 +489,6 @@ impl<T, A: AllocRef> RawVec<T, A> {
518489
// much smaller than the number of `T` types.)
519490
fn finish_grow<A>(
520491
new_layout: Result<Layout, LayoutErr>,
521-
placement: ReallocPlacement,
522492
current_memory: Option<(NonNull<u8>, Layout)>,
523493
alloc: &mut A,
524494
) -> Result<MemoryBlock, TryReserveError>
@@ -532,12 +502,9 @@ where
532502

533503
let memory = if let Some((ptr, old_layout)) = current_memory {
534504
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) }
536506
} else {
537-
match placement {
538-
MayMove => alloc.alloc(new_layout, Uninitialized),
539-
InPlace => Err(AllocErr),
540-
}
507+
alloc.alloc(new_layout, Uninitialized)
541508
}
542509
.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })?;
543510

0 commit comments

Comments
 (0)