Rollup merge of #72366 - nnethercote:tiny-vecs-are-dumb-followup, r=Amanieu
Adjust the zero check in `RawVec::grow`. This was supposed to land as part of #72227. (I wish `git push` would abort when you have uncommited changes.) r? @Amanieu
This commit is contained in:
commit
51f80b7630
@ -401,16 +401,15 @@ fn grow_amortized(
|
|||||||
needed_extra_capacity: usize,
|
needed_extra_capacity: usize,
|
||||||
placement: ReallocPlacement,
|
placement: ReallocPlacement,
|
||||||
) -> Result<(), TryReserveError> {
|
) -> Result<(), TryReserveError> {
|
||||||
|
// This is ensured by the calling contexts.
|
||||||
|
debug_assert!(needed_extra_capacity > 0);
|
||||||
|
|
||||||
if mem::size_of::<T>() == 0 {
|
if mem::size_of::<T>() == 0 {
|
||||||
// Since we return a capacity of `usize::MAX` when `elem_size` is
|
// Since we return a capacity of `usize::MAX` when `elem_size` is
|
||||||
// 0, getting to here necessarily means the `RawVec` is overfull.
|
// 0, getting to here necessarily means the `RawVec` is overfull.
|
||||||
return Err(CapacityOverflow);
|
return Err(CapacityOverflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if needed_extra_capacity == 0 {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nothing we can really do about these checks, sadly.
|
// Nothing we can really do about these checks, sadly.
|
||||||
let required_cap =
|
let required_cap =
|
||||||
used_capacity.checked_add(needed_extra_capacity).ok_or(CapacityOverflow)?;
|
used_capacity.checked_add(needed_extra_capacity).ok_or(CapacityOverflow)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user