Skip to content

Commit 4c109f7

Browse files
committed
index: add method for checking range on DenseBitSet
1 parent a88fc0e commit 4c109f7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

compiler/rustc_index/src/bit_set.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,28 @@ impl<T: Idx> DenseBitSet<T> {
234234
self.clear_excess_bits();
235235
}
236236

237+
/// Checks whether any bit in the given range is a 1.
238+
#[inline]
239+
pub fn contains_any(&self, elems: impl RangeBounds<T>) -> bool {
240+
let Some((start, end)) = inclusive_start_end(elems, self.domain_size) else {
241+
return true;
242+
};
243+
let (start_word_index, start_mask) = word_index_and_mask(start);
244+
let (end_word_index, end_mask) = word_index_and_mask(end);
245+
246+
if self.words[start_word_index] & (!start_mask | !(start_mask - 1)) != 0 {
247+
return true;
248+
}
249+
250+
let remaining = start_word_index + 1..end_word_index;
251+
if !remaining.is_empty() {
252+
self.words[remaining].iter().position(|&w| w != 0).is_some()
253+
|| self.words[end_word_index] & (end_mask | (end_mask - 1)) != 0
254+
} else {
255+
false
256+
}
257+
}
258+
237259
/// Returns `true` if the set has changed.
238260
#[inline]
239261
pub fn remove(&mut self, elem: T) -> bool {

src/tools/miri/src/alloc/isolated_alloc.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ impl IsolatedAlloc {
145145
if pinfo.domain_size() < offset_pinfo + size_pinfo {
146146
break;
147147
}
148-
// FIXME: is there a more efficient way to check whether the entire range is unset
149-
// in the bitset?
150-
let range_avail = !(offset_pinfo..offset_pinfo + size_pinfo).any(|i| pinfo.contains(i));
151-
if range_avail {
148+
if !pinfo.contains_any(offset_pinfo..offset_pinfo + size_pinfo) {
152149
pinfo.insert_range(offset_pinfo..offset_pinfo + size_pinfo);
153150
// SAFETY: We checked the available bytes after `idx` in the call
154151
// to `domain_size` above and asserted there are at least `idx +

0 commit comments

Comments
 (0)