Skip to content

Commit d0cf651

Browse files
DarksonnYuryNorov
authored andcommitted
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>
1 parent f5535d7 commit d0cf651

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

rust/kernel/bitmap.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ impl BitmapVec {
230230
/// The maximum length that uses the inline representation.
231231
pub const MAX_INLINE_LEN: usize = usize::BITS as usize;
232232

233+
/// Construct a longest possible inline [`BitmapVec`].
234+
#[inline]
235+
pub fn new_inline() -> Self {
236+
// INVARIANT: `nbits <= MAX_INLINE_LEN`, so an inline bitmap is the right repr.
237+
BitmapVec {
238+
repr: BitmapRepr { bitmap: 0 },
239+
nbits: BitmapVec::MAX_INLINE_LEN,
240+
}
241+
}
242+
233243
/// Constructs a new [`BitmapVec`].
234244
///
235245
/// Fails with [`AllocError`] when the [`BitmapVec`] could not be allocated. This

0 commit comments

Comments
 (0)