Skip to content

Commit d808d28

Browse files
Rollup merge of rust-lang#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#93984) does the simple thing here and just overwrites every chunk with `Chunk::Ones`. (That fill was then made somewhat easier by rust-lang#145480, which removes the chunk size from all-zero/all-one chunks.) r? nnethercote (or compiler)
2 parents 3938f42 + 9ff52bf commit d808d28

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

compiler/rustc_index/src/bit_set.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,7 @@ impl<T: Idx> ChunkedBitSet<T> {
585585
}
586586

587587
pub fn clear(&mut self) {
588-
let domain_size = self.domain_size();
589-
*self = ChunkedBitSet::new_empty(domain_size);
588+
self.chunks.fill_with(|| Chunk::Zeros);
590589
}
591590

592591
#[cfg(test)]
@@ -684,9 +683,7 @@ impl<T: Idx> ChunkedBitSet<T> {
684683

685684
/// Sets all bits to true.
686685
pub fn insert_all(&mut self) {
687-
for chunk in self.chunks.iter_mut() {
688-
*chunk = Ones;
689-
}
686+
self.chunks.fill_with(|| Chunk::Ones);
690687
}
691688

692689
/// Returns `true` if the set has changed.

0 commit comments

Comments
 (0)