Skip to content

Commit 701ca72

Browse files
Auto merge of #147619 - nnethercote:union-ne-check, r=<try>
Add a `!=` check to `ChunkedBitSet::union`.
2 parents 2300c2a + b1eb8e1 commit 701ca72

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

compiler/rustc_index/src/bit_set.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -799,17 +799,26 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
799799
Mixed(_other_chunk_count, other_chunk_words),
800800
) => {
801801
// First check if the operation would change
802-
// `self_chunk.words`. If not, we can avoid allocating some
803-
// words, and this happens often enough that it's a
804-
// performance win. Also, we only need to operate on the
805-
// in-use words, hence the slicing.
802+
// `self_chunk.words`. (The `bitwise_changes` call alone
803+
// would answer this question, but first check if
804+
// `self_chunks_words` and `other_chunk_words` are unequal,
805+
// because that's a faster check than `bitwise_changes` and
806+
// very often succeeds.)
807+
//
808+
// If not, we can avoid doing the mutation, and this
809+
// avoidance happens often enough that it's a performance
810+
// win. Also, we only need to operate on the in-use words,
811+
// hence the slicing.
806812
let op = |a, b| a | b;
807813
let num_words = num_words(chunk_domain_size as usize);
808-
if bitwise_changes(
809-
&self_chunk_words[0..num_words],
810-
&other_chunk_words[0..num_words],
811-
op,
812-
) {
814+
815+
if self_chunk_words[0..num_words] != other_chunk_words[0..num_words]
816+
&& bitwise_changes(
817+
&self_chunk_words[0..num_words],
818+
&other_chunk_words[0..num_words],
819+
op,
820+
)
821+
{
813822
let self_chunk_words = Rc::make_mut(self_chunk_words);
814823
let has_changed = bitwise(
815824
&mut self_chunk_words[0..num_words],

0 commit comments

Comments
 (0)