diff --git a/fuzz/fuzz_targets/main.rs b/fuzz/fuzz_targets/main.rs index 35286542..91b8f615 100644 --- a/fuzz/fuzz_targets/main.rs +++ b/fuzz/fuzz_targets/main.rs @@ -157,9 +157,9 @@ fn test_with_inline_cap( small_vec = SmallVec::new(); std_vec = Vec::new(); } - Op::WithCapacity(cap) => { - small_vec = SmallVec::with_capacity(cap.0); - std_vec = Vec::with_capacity(cap.0); + Op::WithCapacity(capacity) => { + small_vec = SmallVec::with_capacity(capacity.0); + std_vec = Vec::with_capacity(capacity.0); } #[allow(deprecated)] Op::FromVec => { diff --git a/src/conversions.rs b/src/conversions.rs index 05ffb046..96b134e4 100644 --- a/src/conversions.rs +++ b/src/conversions.rs @@ -146,18 +146,18 @@ impl From< as Like>::Type> let length = vec.len(); // A heap-allocated `SmallVec` must always observe the invariant - // that `cap > INLINE`. + // that `capacity > INLINE`. if vec.capacity() <= INLINE { vec.reserve(INLINE + 1 - length); } - let cap = vec.capacity(); + let capacity = vec.capacity(); // SAFETY: vec.capacity is not `0` (checked above), so the pointer // can not dangle and thus specifically cannot be null. let pointer = unsafe { NonNull::new_unchecked(vec.as_mut_ptr()) }; Self { length: LocatedLength::new(length, true), - raw: RawSmallVec::heap(pointer, cap), + raw: RawSmallVec::heap(pointer, capacity), allocator: Global } } @@ -186,14 +186,18 @@ impl From as Like>::Type::from_raw_parts(pointer.as_ptr(), length, cap) + let (pointer, capacity) = this.raw.heap; + as Like>::Type::from_raw_parts( + pointer.as_ptr(), + length, + capacity + ) } } } diff --git a/src/lib.rs b/src/lib.rs index 30bf7c72..7cc8b0b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -660,7 +660,7 @@ impl SmallVec { if on_heap { unsafe { // SAFETY: heap member is active - let (pointer, old_cap) = self.raw.heap; + let (pointer, old_capacity) = self.raw.heap; // inline member is now active // SAFETY: length <= new_capacity <= Self::inline_size() @@ -668,7 +668,7 @@ impl SmallVec { copy_nonoverlapping(pointer.as_ptr(), self.raw.as_mut_ptr_inline(), length); drop(DropDealloc { pointer: pointer.cast(), - size_bytes: old_cap * size_of::(), + size_bytes: old_capacity * size_of::(), align: align_of::(), allocator: &self.allocator }); @@ -695,10 +695,10 @@ impl SmallVec { .checked_add(additional) .ok_or(SmallVecError::CapacityOverflow)?; - let double_cap = self.capacity().saturating_mul(2); + let double_capacity = self.capacity().saturating_mul(2); let new_capacity = required - .max(double_cap) + .max(double_capacity) .checked_next_power_of_two() .ok_or(SmallVecError::CapacityOverflow)?; @@ -1894,12 +1894,12 @@ unsafe impl BufMut for SmallVec 1); + let (pointer, capacity) = unsafe { raw.heap }; + assert!(capacity > 1); // SAFETY: parts come straight from `into_parts`. let rebuilt = unsafe { SmallVec::::from_parts(raw, length) };