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:
Guillaume Gomez
2025-10-13 11:25:23 +02:00
committed by GitHub
+2 -5
View File
@@ -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.