mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 04:04:43 +01:00
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>
This commit is contained in:
parent
6297fb3863
commit
69ec6a1bed
1 changed files with 19 additions and 0 deletions
|
|
@ -93,6 +93,18 @@ impl ReallocRequest {
|
|||
}
|
||||
|
||||
impl IdPool {
|
||||
/// Constructs a new [`IdPool`].
|
||||
///
|
||||
/// The pool will have a capacity of [`MAX_INLINE_LEN`].
|
||||
///
|
||||
/// [`MAX_INLINE_LEN`]: BitmapVec::MAX_INLINE_LEN
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
map: BitmapVec::new_inline(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructs a new [`IdPool`] with space for a specific number of bits.
|
||||
///
|
||||
/// A capacity below [`MAX_INLINE_LEN`] is adjusted to [`MAX_INLINE_LEN`].
|
||||
|
|
@ -229,3 +241,10 @@ impl IdPool {
|
|||
self.map.clear_bit(id);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for IdPool {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue