about summary refs log tree commit diff
path: root/compiler/rustc_index/src/bit_set.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-11-23 13:14:29 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-11-29 17:01:48 +1100
commitff780025663189ac7ec81d40a7cf309e45bd056a (patch)
tree8fa959f32397ff8233dedc30e730147b89854eee /compiler/rustc_index/src/bit_set.rs
parent15b24c46b462d7baf5b1b80656d3ec3c46c73a60 (diff)
downloadrust-ff780025663189ac7ec81d40a7cf309e45bd056a.tar.gz
rust-ff780025663189ac7ec81d40a7cf309e45bd056a.zip
Tiny `ChunkedBitSet` improvements.
- Fix a typo in a comment.
- Remove unnecessary `Chunk::` qualifiers.
- Rename `ChunkedBitIter::bitset` as `ChunkedBitIter::bit_set`, because
  `bit_set` is the form used everywhere else.
- Avoid some unnecessary local variables.
Diffstat (limited to 'compiler/rustc_index/src/bit_set.rs')
-rw-r--r--compiler/rustc_index/src/bit_set.rs35
1 files changed, 16 insertions, 19 deletions
diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs
index 4295ec3f63f..0d52e717391 100644
--- a/compiler/rustc_index/src/bit_set.rs
+++ b/compiler/rustc_index/src/bit_set.rs
@@ -383,8 +383,7 @@ enum Chunk {
     /// turns out to be both simpler and have better performance than
     /// allocating the minimum number of words, largely because we avoid having
     /// to store the length, which would make this type larger. These excess
-    /// words are always be zero, as are any excess bits in the final in-use
-    /// word.
+    /// words are always zero, as are any excess bits in the final in-use word.
     ///
     /// The first `ChunkSize` field is always non-zero.
     ///
@@ -465,7 +464,7 @@ impl<T: Idx> ChunkedBitSet<T> {
     }
 
     pub fn is_empty(&self) -> bool {
-        self.chunks.iter().all(|chunk| matches!(chunk, Chunk::Zeros(..)))
+        self.chunks.iter().all(|chunk| matches!(chunk, Zeros(..)))
     }
 
     /// Returns `true` if `self` contains `elem`.
@@ -855,7 +854,7 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for BitSet<T> {
                 words = &mut words[..CHUNK_WORDS];
             }
             match chunk {
-                Chunk::Zeros(..) => {
+                Zeros(..) => {
                     for word in words {
                         if *word != 0 {
                             changed = true;
@@ -863,8 +862,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for BitSet<T> {
                         }
                     }
                 }
-                Chunk::Ones(..) => (),
-                Chunk::Mixed(_, _, data) => {
+                Ones(..) => (),
+                Mixed(_, _, data) => {
                     for (i, word) in words.iter_mut().enumerate() {
                         let new_val = *word & data[i];
                         if new_val != *word {
@@ -902,22 +901,22 @@ impl<T> Clone for ChunkedBitSet<T> {
 
 pub struct ChunkedBitIter<'a, T: Idx> {
     index: usize,
-    bitset: &'a ChunkedBitSet<T>,
+    bit_set: &'a ChunkedBitSet<T>,
 }
 
 impl<'a, T: Idx> ChunkedBitIter<'a, T> {
     #[inline]
-    fn new(bitset: &'a ChunkedBitSet<T>) -> ChunkedBitIter<'a, T> {
-        ChunkedBitIter { index: 0, bitset }
+    fn new(bit_set: &'a ChunkedBitSet<T>) -> ChunkedBitIter<'a, T> {
+        ChunkedBitIter { index: 0, bit_set }
     }
 }
 
 impl<'a, T: Idx> Iterator for ChunkedBitIter<'a, T> {
     type Item = T;
     fn next(&mut self) -> Option<T> {
-        while self.index < self.bitset.domain_size() {
+        while self.index < self.bit_set.domain_size() {
             let elem = T::new(self.index);
-            let chunk = &self.bitset.chunks[chunk_index(elem)];
+            let chunk = &self.bit_set.chunks[chunk_index(elem)];
             match &chunk {
                 Zeros(chunk_domain_size) => {
                     self.index += *chunk_domain_size as usize;
@@ -954,17 +953,17 @@ impl<'a, T: Idx> Iterator for ChunkedBitIter<'a, T> {
             init = f(init, item);
         }
         let start_chunk = self.index / CHUNK_BITS;
-        let chunks = &self.bitset.chunks[start_chunk..];
+        let chunks = &self.bit_set.chunks[start_chunk..];
         for (i, chunk) in chunks.iter().enumerate() {
             let base = (start_chunk + i) * CHUNK_BITS;
             match chunk {
-                Chunk::Zeros(_) => (),
-                Chunk::Ones(limit) => {
+                Zeros(_) => (),
+                Ones(limit) => {
                     for j in 0..(*limit as usize) {
                         init = f(init, T::new(base + j));
                     }
                 }
-                Chunk::Mixed(_, _, words) => {
+                Mixed(_, _, words) => {
                     init = BitIter::new(&**words).fold(init, |val, mut item: T| {
                         item.increment_by(base);
                         f(val, item)
@@ -1302,15 +1301,13 @@ impl<'a, T: Idx> Iterator for BitIter<'a, T> {
                 // Get the position of the next set bit in the current word,
                 // then clear the bit.
                 let bit_pos = self.word.trailing_zeros() as usize;
-                let bit = 1 << bit_pos;
-                self.word ^= bit;
+                self.word ^= 1 << bit_pos;
                 return Some(T::new(bit_pos + self.offset));
             }
 
             // Move onto the next word. `wrapping_add()` is needed to handle
             // the degenerate initial value given to `offset` in `new()`.
-            let word = self.iter.next()?;
-            self.word = *word;
+            self.word = *self.iter.next()?;
             self.offset = self.offset.wrapping_add(WORD_BITS);
         }
     }