perf: pre-allocation of SequenceNumberSet

Support pre-allocation of SequenceNumberSet for known-length sets.
pull/24376/head
Dom Dwyer 2023-03-03 17:08:48 +01:00
parent 7801a63334
commit 146494f619
No known key found for this signature in database
GPG Key ID: E4C40DBD9157879A
1 changed files with 6 additions and 0 deletions

View File

@ -66,6 +66,12 @@ impl SequenceNumberSet {
pub fn iter(&self) -> impl Iterator<Item = SequenceNumber> + '_ {
self.0.iter().map(|v| SequenceNumber::new(v as _))
}
/// Initialise a [`SequenceNumberSet`] that is pre-allocated to contain up
/// to `n` elements without reallocating.
pub fn with_capacity(n: u32) -> Self {
Self(croaring::Bitmap::create_with_capacity(n))
}
}
/// Deserialisation method.