mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-29 11:51:31 +03:00
Rollup merge of #147623 - Zalathar:clear-mixed, r=nnethercote
Clear `ChunkedBitSet` without reallocating There doesn't appear to be any reason to clear a ChunkedBitSet via its constructor (which allocates a new list of chunks), when we could just fill the existing allocation with `Chunk::Zeros` instead. For comparison, the `insert_all` impl added by the same PR (rust-lang/rust#93984) does the simple thing here and just overwrites every chunk with `Chunk::Ones`. (That fill was then made somewhat easier by rust-lang/rust#145480, which removes the chunk size from all-zero/all-one chunks.) r? nnethercote (or compiler)
This commit is contained in:
@@ -585,8 +585,7 @@ pub fn new_filled(domain_size: usize) -> Self {
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
let domain_size = self.domain_size();
|
||||
*self = ChunkedBitSet::new_empty(domain_size);
|
||||
self.chunks.fill_with(|| Chunk::Zeros);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -684,9 +683,7 @@ pub fn insert(&mut self, elem: T) -> bool {
|
||||
|
||||
/// Sets all bits to true.
|
||||
pub fn insert_all(&mut self) {
|
||||
for chunk in self.chunks.iter_mut() {
|
||||
*chunk = Ones;
|
||||
}
|
||||
self.chunks.fill_with(|| Chunk::Ones);
|
||||
}
|
||||
|
||||
/// Returns `true` if the set has changed.
|
||||
|
||||
Reference in New Issue
Block a user