File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,28 @@ impl<T: Idx> DenseBitSet<T> {
234
234
self . clear_excess_bits ( ) ;
235
235
}
236
236
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
+
237
259
/// Returns `true` if the set has changed.
238
260
#[ inline]
239
261
pub fn remove ( & mut self , elem : T ) -> bool {
Original file line number Diff line number Diff line change @@ -145,10 +145,7 @@ impl IsolatedAlloc {
145
145
if pinfo. domain_size ( ) < offset_pinfo + size_pinfo {
146
146
break ;
147
147
}
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) {
152
149
pinfo. insert_range ( offset_pinfo..offset_pinfo + size_pinfo) ;
153
150
// SAFETY: We checked the available bytes after `idx` in the call
154
151
// to `domain_size` above and asserted there are at least `idx +
You can’t perform that action at this time.
0 commit comments