Skip to content

Commit

Permalink
feat!: renamed unchecked_push* methods to push*_unchecked for mor…
Browse files Browse the repository at this point in the history
…e conventional naming
  • Loading branch information
bluurryy committed Dec 22, 2024
1 parent 8de6fb6 commit 24a9026
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased
- **breaking:** renamed `unchecked_push` to `push_unchecked`
- **breaking:** renamed `unchecked_push_with` to `push_with_unchecked`

## 0.14.0 (2024-12-12)
- **breaking:** fix `scoped_aligned`'s closure to take a `BumpScope` with `NEW_MIN_ALIGN` instead of `MIN_ALIGN`
- **breaking:** `aligned`'s closure now takes a `BumpScope` with lifetime `'a` instead of `'_`
Expand Down
2 changes: 1 addition & 1 deletion src/bump_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ where
while vec.len() != vec.capacity() {
match iter.next() {
// SAFETY: we checked above that `len != capacity`, so there is space
Some(value) => unsafe { vec.unchecked_push(value) },
Some(value) => unsafe { vec.push_unchecked(value) },
None => break,
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/bump_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ impl<T, A: BumpAllocator> BumpVec<T, A> {
unsafe {
if count != 0 {
for _ in 0..(count - 1) {
vec.unchecked_push_with(|| value.clone());
vec.push_with_unchecked(|| value.clone());
}

vec.unchecked_push_with(|| value);
vec.push_with_unchecked(|| value);
}
}

Expand Down Expand Up @@ -429,7 +429,7 @@ impl<T, A: BumpAllocator> BumpVec<T, A> {
while vec.len() != vec.capacity() {
match iter.next() {
// SAFETY: we checked above that `len != capacity`, so there is space
Some(value) => unsafe { vec.unchecked_push(value) },
Some(value) => unsafe { vec.push_unchecked(value) },
None => break,
}
}
Expand Down Expand Up @@ -707,17 +707,17 @@ impl<T, A: BumpAllocator> BumpVec<T, A> {
/// # Safety
/// Vector must not be full.
#[inline(always)]
pub unsafe fn unchecked_push(&mut self, value: T) {
unsafe { self.fixed.cook_mut() }.unchecked_push(value);
pub unsafe fn push_unchecked(&mut self, value: T) {
unsafe { self.fixed.cook_mut() }.push_unchecked(value);
}

/// Appends an element to the back of the collection.
///
/// # Safety
/// Vector must not be full.
#[inline(always)]
pub unsafe fn unchecked_push_with(&mut self, f: impl FnOnce() -> T) {
unsafe { self.fixed.cook_mut() }.unchecked_push_with(f);
pub unsafe fn push_with_unchecked(&mut self, f: impl FnOnce() -> T) {
unsafe { self.fixed.cook_mut() }.push_with_unchecked(f);
}

/// Forces the length of the vector to `new_len`.
Expand Down Expand Up @@ -781,7 +781,7 @@ impl<T, A: BumpAllocator> BumpVec<T, A> {
use fn generic_push_with(&mut self, f: impl FnOnce() -> T) {
self.generic_reserve_one()?;
unsafe {
self.unchecked_push_with(f);
self.push_with_unchecked(f);
}
Ok(())
}
Expand Down Expand Up @@ -1032,7 +1032,7 @@ impl<T, A: BumpAllocator> BumpVec<T, A> {
let fake = ManuallyDrop::new(MaybeUninit::<T>::uninit().assume_init());

for _ in 0..count {
self.unchecked_push((*fake).clone());
self.push_unchecked((*fake).clone());
}

return Ok(());
Expand Down
10 changes: 5 additions & 5 deletions src/fixed_bump_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ impl<'a, T> FixedBumpVec<'a, T> {
use fn generic_push_with(&mut self, f: impl FnOnce() -> T) {
self.generic_reserve_one()?;
unsafe {
self.unchecked_push_with(f);
self.push_with_unchecked(f);
}
Ok(())
}
Expand Down Expand Up @@ -711,7 +711,7 @@ impl<'a, T> FixedBumpVec<'a, T> {
let fake = ManuallyDrop::new(MaybeUninit::<T>::uninit().assume_init());

for _ in 0..count {
self.unchecked_push((*fake).clone());
self.push_unchecked((*fake).clone());
}

return Ok(());
Expand Down Expand Up @@ -1081,16 +1081,16 @@ impl<'a, T> FixedBumpVec<'a, T> {
/// # Safety
/// Vector must not be full.
#[inline(always)]
pub unsafe fn unchecked_push(&mut self, value: T) {
self.unchecked_push_with(|| value);
pub unsafe fn push_unchecked(&mut self, value: T) {
self.push_with_unchecked(|| value);
}

/// Appends an element to the back of the collection.
///
/// # Safety
/// Vector must not be full.
#[inline(always)]
pub unsafe fn unchecked_push_with(&mut self, f: impl FnOnce() -> T) {
pub unsafe fn push_with_unchecked(&mut self, f: impl FnOnce() -> T) {
debug_assert!(!self.is_full());

let ptr = self.as_mut_ptr().add(self.len());
Expand Down
16 changes: 8 additions & 8 deletions src/mut_bump_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,17 @@ impl<T, A> MutBumpVec<T, A> {
/// # Safety
/// Vector must not be full.
#[inline(always)]
pub unsafe fn unchecked_push(&mut self, value: T) {
unsafe { self.fixed.cook_mut() }.unchecked_push(value);
pub unsafe fn push_unchecked(&mut self, value: T) {
unsafe { self.fixed.cook_mut() }.push_unchecked(value);
}

/// Appends an element to the back of the collection.
///
/// # Safety
/// Vector must not be full.
#[inline(always)]
pub unsafe fn unchecked_push_with(&mut self, f: impl FnOnce() -> T) {
unsafe { self.fixed.cook_mut() }.unchecked_push_with(f);
pub unsafe fn push_with_unchecked(&mut self, f: impl FnOnce() -> T) {
unsafe { self.fixed.cook_mut() }.push_with_unchecked(f);
}

/// Forces the length of the vector to `new_len`.
Expand Down Expand Up @@ -490,10 +490,10 @@ impl<T, A: MutBumpAllocator> MutBumpVec<T, A> {
unsafe {
if count != 0 {
for _ in 0..(count - 1) {
vec.unchecked_push_with(|| value.clone());
vec.push_with_unchecked(|| value.clone());
}

vec.unchecked_push_with(|| value);
vec.push_with_unchecked(|| value);
}
}

Expand Down Expand Up @@ -610,7 +610,7 @@ impl<T, A: MutBumpAllocator> MutBumpVec<T, A> {
use fn generic_push_with(&mut self, f: impl FnOnce() -> T) {
self.generic_reserve_one()?;
unsafe {
self.unchecked_push_with(f);
self.push_with_unchecked(f);
}
Ok(())
}
Expand Down Expand Up @@ -862,7 +862,7 @@ impl<T, A: MutBumpAllocator> MutBumpVec<T, A> {
let fake = ManuallyDrop::new(MaybeUninit::<T>::uninit().assume_init());

for _ in 0..count {
self.unchecked_push((*fake).clone());
self.push_unchecked((*fake).clone());
}

return Ok(());
Expand Down
14 changes: 7 additions & 7 deletions src/mut_bump_vec_rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ impl<T, A> MutBumpVecRev<T, A> {
/// # Safety
/// Vector must not be full.
#[inline(always)]
pub unsafe fn unchecked_push(&mut self, value: T) {
self.unchecked_push_with(|| value);
pub unsafe fn push_unchecked(&mut self, value: T) {
self.push_with_unchecked(|| value);
}

/// Appends an element to the back of the collection.
///
/// # Safety
/// Vector must not be full.
#[inline(always)]
pub unsafe fn unchecked_push_with(&mut self, f: impl FnOnce() -> T) {
pub unsafe fn push_with_unchecked(&mut self, f: impl FnOnce() -> T) {
debug_assert!(self.len < self.cap);

let ptr = nonnull::sub(self.end, self.len + 1);
Expand Down Expand Up @@ -575,10 +575,10 @@ impl<T, A: MutBumpAllocator> MutBumpVecRev<T, A> {
unsafe {
if count != 0 {
for _ in 0..(count - 1) {
vec.unchecked_push_with(|| value.clone());
vec.push_with_unchecked(|| value.clone());
}

vec.unchecked_push_with(|| value);
vec.push_with_unchecked(|| value);
}
}

Expand Down Expand Up @@ -707,7 +707,7 @@ impl<T, A: MutBumpAllocator> MutBumpVecRev<T, A> {
use fn generic_push_with(&mut self, f: impl FnOnce() -> T) {
self.generic_reserve_one()?;
unsafe {
self.unchecked_push_with(f);
self.push_with_unchecked(f);
}
Ok(())
}
Expand Down Expand Up @@ -1280,7 +1280,7 @@ impl<T, A: MutBumpAllocator> MutBumpVecRev<T, A> {
let fake = ManuallyDrop::new(MaybeUninit::<T>::uninit().assume_init());

for _ in 0..count {
self.unchecked_push((*fake).clone());
self.push_unchecked((*fake).clone());
}

return Ok(());
Expand Down

0 comments on commit 24a9026

Please sign in to comment.