Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ce37f0a

Browse files
committed
Add comments
1 parent d73a169 commit ce37f0a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compiler/rustc_index/src/bit_set.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ impl<T: Idx> BitRelations<BitSet<T>> for BitSet<T> {
247247
}
248248
}
249249

250+
// Applies a function to mutate a bitset, and returns true if any
251+
// of the applications return true
250252
fn sequential_update<T: Idx>(
251253
mut self_update: impl FnMut(T) -> bool,
252254
it: impl Iterator<Item = T>,
@@ -258,6 +260,8 @@ fn sequential_update<T: Idx>(
258260
changed
259261
}
260262

263+
// Optimization of intersection for SparseBitSet that's generic
264+
// over the RHS
261265
fn sparse_intersect<T: Idx>(
262266
set: &mut SparseBitSet<T>,
263267
other_contains: impl Fn(&T) -> bool,
@@ -267,6 +271,10 @@ fn sparse_intersect<T: Idx>(
267271
set.elems.len() != size
268272
}
269273

274+
// Optimization of dense/sparse intersection. The resulting set is
275+
// guaranteed to be at most the size of the sparse set, and hence can be
276+
// represented as a sparse set. Therefore the sparse set is copied and filtered,
277+
// then returned as the new set.
270278
fn dense_sparse_intersect<T: Idx>(
271279
dense: &BitSet<T>,
272280
sparse: &SparseBitSet<T>,
@@ -303,6 +311,10 @@ impl<T: Idx> BitRelations<HybridBitSet<T>> for BitSet<T> {
303311
match other {
304312
HybridBitSet::Sparse(sparse) => {
305313
let (updated, changed) = dense_sparse_intersect(self, sparse);
314+
315+
// We can't directly assign the BitSet to the SparseBitSet, and
316+
// doing `*self = updated.to_dense()` would cause a drop / reallocation. Instead,
317+
// the BitSet is cleared and `updated` is copied into `self`.
306318
self.clear();
307319
for elem in updated.iter() {
308320
self.insert(*elem);

0 commit comments

Comments
 (0)