File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Expand file tree Collapse file tree 2 files changed +24
-8
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 @@ -141,14 +141,8 @@ impl IsolatedAlloc {
141
141
for offset in ( 0 ..page_size) . step_by ( layout. align ( ) ) {
142
142
let offset_pinfo = offset / COMPRESSION_FACTOR ;
143
143
let size_pinfo = layout. size ( ) / COMPRESSION_FACTOR ;
144
- // DenseBitSet::contains() panics if the index is out of bounds
145
- if pinfo. domain_size ( ) < offset_pinfo + size_pinfo {
146
- break ;
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 {
144
+ // DenseBitSet::contains_any() returns true on OOB indexing
145
+ if !pinfo. contains_any ( offset_pinfo..offset_pinfo + size_pinfo) {
152
146
pinfo. insert_range ( offset_pinfo..offset_pinfo + size_pinfo) ;
153
147
// SAFETY: We checked the available bytes after `idx` in the call
154
148
// to `domain_size` above and asserted there are at least `idx +
You can’t perform that action at this time.
0 commit comments