Skip to content

Commit 69ec6a1

Browse files
DarksonnYuryNorov
authored andcommitted
rust: id_pool: do not supply starting capacity
Rust Binder wants to use inline bitmaps whenever possible to avoid allocations, so introduce a constructor for an IdPool with arbitrary capacity that stores the bitmap inline. The existing constructor could be renamed to with_capacity() to match constructors for other similar types, but it is removed as there is currently no user for it. [Miguel: rust: id_pool: fix broken intra-doc link] 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 6297fb3 commit 69ec6a1

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

rust/kernel/id_pool.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ impl ReallocRequest {
9393
}
9494

9595
impl IdPool {
96+
/// Constructs a new [`IdPool`].
97+
///
98+
/// The pool will have a capacity of [`MAX_INLINE_LEN`].
99+
///
100+
/// [`MAX_INLINE_LEN`]: BitmapVec::MAX_INLINE_LEN
101+
#[inline]
102+
pub fn new() -> Self {
103+
Self {
104+
map: BitmapVec::new_inline(),
105+
}
106+
}
107+
96108
/// Constructs a new [`IdPool`] with space for a specific number of bits.
97109
///
98110
/// A capacity below [`MAX_INLINE_LEN`] is adjusted to [`MAX_INLINE_LEN`].
@@ -229,3 +241,10 @@ impl IdPool {
229241
self.map.clear_bit(id);
230242
}
231243
}
244+
245+
impl Default for IdPool {
246+
#[inline]
247+
fn default() -> Self {
248+
Self::new()
249+
}
250+
}

0 commit comments

Comments
 (0)