]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: bitmap: add BitmapVec::new_inline()
authorAlice Ryhl <aliceryhl@google.com>
Tue, 25 Nov 2025 13:59:38 +0000 (13:59 +0000)
committerYury Norov (NVIDIA) <yury.norov@gmail.com>
Wed, 26 Nov 2025 16:25:35 +0000 (11:25 -0500)
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>
rust/kernel/bitmap.rs

index 0705646c6251a49f213a45f1f013cb9eb2ed81de..83d7dea99137ded7cba47ec5a3bf10bb7e13f2d2 100644 (file)
@@ -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