Skip to content

Commit

Permalink
feat: added MutBumpVecRev::unchecked_push(_with)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluurryy committed Oct 14, 2024
1 parent f0bbc95 commit 1e92c71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## Unreleased
- **added:** `MutBumpVecRev::{ append, into_flattened, as_non_null_{ptr, slice} }`
- **added:** `MutBumpVecRev::{ append, into_flattened, unchecked_push(_with), as_non_null_(ptr, slice) }`
- **fixed:** `MutBumpVecRev::extend_from_within_clone` doing nothing for ZSTs
- **fixed:** potential UB in `MutBumpVecRev::extend_from_slice_clone` when clone panics

Expand Down
12 changes: 10 additions & 2 deletions src/mut_bump_vec_rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,21 @@ impl<'b, 'a: 'b, T, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_
self.len == 0
}

/// Appends an element to the back of the collection.
///
/// # Safety
/// Vector must not be full.
#[inline(always)]
unsafe fn unchecked_push(&mut self, value: T) {
pub unsafe fn unchecked_push(&mut self, value: T) {
self.unchecked_push_with(|| value);
}

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

let ptr = nonnull::sub(self.end, self.len + 1);
Expand Down

0 comments on commit 1e92c71

Please sign in to comment.