From 5274d82a34d2a51bb8900fb30294ebe21f19cb12 Mon Sep 17 00:00:00 2001 From: Divyansh Patel Date: Mon, 2 Nov 2026 14:11:08 +0530 Subject: [PATCH 1/2] rename cap to capacity in lib & conversion --- src/conversions.rs | 18 +++++++++++------- src/lib.rs | 18 +++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) 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 Date: Mon, 2 Nov 2026 14:12:35 +0530 Subject: [PATCH 2/2] rename in parts.rs & main.rs --- fuzz/fuzz_targets/main.rs | 6 +++--- tests/parts.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) 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/tests/parts.rs b/tests/parts.rs index bf77ea48..a5030484 100644 --- a/tests/parts.rs +++ b/tests/parts.rs @@ -13,8 +13,8 @@ fn into_from_parts_spilled() { assert_eq!(length.len(), 3); // SAFETY: `length` says on heap, so `heap` is the active member. - let (pointer, cap) = unsafe { raw.heap }; - assert!(cap > 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) };