compiler/rust/bitset: Don't reserve space in remove()

If the requested bit is past the end of the set, we can just return
false.  We don't have to grow the bitset.

Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41915>
This commit is contained in:
Faith Ekstrand 2026-05-21 15:19:22 -04:00 committed by Marge Bot
parent 81c9eddb69
commit ffe6cdd52d

View file

@ -181,10 +181,13 @@ impl<K: IntoBitIndex> BitSet<K> {
pub fn remove(&mut self, key: K) -> bool {
let idx = BitIndex::from(key);
self.reserve_words(idx.word + 1);
let exists = self.words[idx.word] & (1_u32 << idx.bit) != 0;
self.words[idx.word] &= !(1_u32 << idx.bit);
exists
if idx.word < self.words.len() {
let exists = self.words[idx.word] & (1_u32 << idx.bit) != 0;
self.words[idx.word] &= !(1_u32 << idx.bit);
exists
} else {
false
}
}
}