Skip to content

Commit f4d5c48

Browse files
committed
Use BitSet in SparseBitMatrix.
A `ChunkedBitSet` has to be at least 2048 bits for it to outperform a `BitSet`, because that's the chunk size. The largest `SparseBitMatrix` encountered when compiling the compiler and the entire rustc-perf benchmark suite is less than 600 bits. This change is a tiny perf win, but the motivation is more about avoiding uses of `ChunkedBitSet` outside of `MixedBitSet`.
1 parent f901a85 commit f4d5c48

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

compiler/rustc_index/src/bit_set.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ where
15451545
C: Idx,
15461546
{
15471547
num_columns: usize,
1548-
rows: IndexVec<R, Option<ChunkedBitSet<C>>>,
1548+
rows: IndexVec<R, Option<BitSet<C>>>,
15491549
}
15501550

15511551
impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
@@ -1554,10 +1554,10 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
15541554
Self { num_columns, rows: IndexVec::new() }
15551555
}
15561556

1557-
fn ensure_row(&mut self, row: R) -> &mut ChunkedBitSet<C> {
1558-
// Instantiate any missing rows up to and including row `row` with an empty ChunkedBitSet.
1559-
// Then replace row `row` with a full ChunkedBitSet if necessary.
1560-
self.rows.get_or_insert_with(row, || ChunkedBitSet::new_empty(self.num_columns))
1557+
fn ensure_row(&mut self, row: R) -> &mut BitSet<C> {
1558+
// Instantiate any missing rows up to and including row `row` with an empty `BitSet`.
1559+
// Then replace row `row` with a full `BitSet` if necessary.
1560+
self.rows.get_or_insert_with(row, || BitSet::new_empty(self.num_columns))
15611561
}
15621562

15631563
/// Sets the cell at `(row, column)` to true. Put another way, insert
@@ -1631,7 +1631,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
16311631
self.row(row).into_iter().flat_map(|r| r.iter())
16321632
}
16331633

1634-
pub fn row(&self, row: R) -> Option<&ChunkedBitSet<C>> {
1634+
pub fn row(&self, row: R) -> Option<&BitSet<C>> {
16351635
self.rows.get(row)?.as_ref()
16361636
}
16371637

@@ -1641,7 +1641,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
16411641
/// Returns true if the row was changed.
16421642
pub fn intersect_row<Set>(&mut self, row: R, set: &Set) -> bool
16431643
where
1644-
ChunkedBitSet<C>: BitRelations<Set>,
1644+
BitSet<C>: BitRelations<Set>,
16451645
{
16461646
match self.rows.get_mut(row) {
16471647
Some(Some(row)) => row.intersect(set),
@@ -1655,7 +1655,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
16551655
/// Returns true if the row was changed.
16561656
pub fn subtract_row<Set>(&mut self, row: R, set: &Set) -> bool
16571657
where
1658-
ChunkedBitSet<C>: BitRelations<Set>,
1658+
BitSet<C>: BitRelations<Set>,
16591659
{
16601660
match self.rows.get_mut(row) {
16611661
Some(Some(row)) => row.subtract(set),
@@ -1669,7 +1669,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
16691669
/// Returns true if the row was changed.
16701670
pub fn union_row<Set>(&mut self, row: R, set: &Set) -> bool
16711671
where
1672-
ChunkedBitSet<C>: BitRelations<Set>,
1672+
BitSet<C>: BitRelations<Set>,
16731673
{
16741674
self.ensure_row(row).union(set)
16751675
}

0 commit comments

Comments
 (0)