Skip to content

Commit

Permalink
feat: expose smallvec_with
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 30, 2024
1 parent a1a114d commit 689ddc9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ extern crate alloc;

mod nibbles;
pub use nibbles::{
common_prefix_length, get_byte, get_byte_unchecked, pack_to, pack_to_unchecked, Nibbles,
common_prefix_length, get_byte, get_byte_unchecked, pack_to, pack_to_unchecked, smallvec_with,
Nibbles,
};
4 changes: 3 additions & 1 deletion src/nibbles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,13 @@ pub fn common_prefix_length(a: &[u8], b: &[u8]) -> usize {

/// Initializes a smallvec with the given length and a closure that initializes the buffer.
///
/// Optimized version of `SmallVec::with_capacity` + `f()` + `.set_len`.
///
/// # Safety
///
/// The closure must fully initialize the buffer with the given length.
#[inline]
unsafe fn smallvec_with<const N: usize>(
pub unsafe fn smallvec_with<const N: usize>(
len: usize,
f: impl FnOnce(&mut [MaybeUninit<u8>]),
) -> SmallVec<[u8; N]> {
Expand Down

0 comments on commit 689ddc9

Please sign in to comment.