mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:04:41 +01:00
rust: bitmap: add BitmapVec::new_inline()
This constructor is useful when you just want to create a BitmapVec without allocating but don't care how large it is. Acked-by: Yury Norov (NVIDIA) <yury.norov@gmail.com> Reviewed-by: Burak Emir <bqe@google.com> Reviewed-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
This commit is contained in:
parent
f5535d78e1
commit
d0cf6512bb
1 changed files with 10 additions and 0 deletions
|
|
@ -230,6 +230,16 @@ impl BitmapVec {
|
|||
/// The maximum length that uses the inline representation.
|
||||
pub const MAX_INLINE_LEN: usize = usize::BITS as usize;
|
||||
|
||||
/// Construct a longest possible inline [`BitmapVec`].
|
||||
#[inline]
|
||||
pub fn new_inline() -> Self {
|
||||
// INVARIANT: `nbits <= MAX_INLINE_LEN`, so an inline bitmap is the right repr.
|
||||
BitmapVec {
|
||||
repr: BitmapRepr { bitmap: 0 },
|
||||
nbits: BitmapVec::MAX_INLINE_LEN,
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructs a new [`BitmapVec`].
|
||||
///
|
||||
/// Fails with [`AllocError`] when the [`BitmapVec`] could not be allocated. This
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue