Re: [PATCH v5 2/6] rust: bitmap: add BitmapVec::new_inline()
From: Yury Norov
Date: Wed Nov 12 2025 - 10:36:37 EST
On Wed, Nov 12, 2025 at 12:47:20PM +0000, Alice Ryhl wrote:
> 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@xxxxxxxxx>
> Reviewed-by: Burak Emir <bqe@xxxxxxxxxx>
> Reviewed-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> ---
> rust/kernel/bitmap.rs | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs
> index 0705646c6251a49f213a45f1f013cb9eb2ed81de..bbbf0f9e5d9251953584581af57042143447b996 100644
> --- a/rust/kernel/bitmap.rs
> +++ b/rust/kernel/bitmap.rs
> @@ -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 <= NO_ALLOC_MAX_LEN`, so an inline bitmap is the right repr.
> + BitmapVec {
> + repr: BitmapRepr { bitmap: 0 },
> + nbits: BitmapVec::NO_ALLOC_MAX_LEN,
This should be MAX_INLINE_LEN, I guess?
> + }
> + }
> +
> /// Constructs a new [`BitmapVec`].
> ///
> /// Fails with [`AllocError`] when the [`BitmapVec`] could not be allocated. This
>
> --
> 2.51.2.1041.gc1ab5b90ca-goog