File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -187,14 +187,18 @@ impl<T: Idx> DenseBitSet<T> {
187
187
/// Insert `elem`. Returns whether the set has changed.
188
188
#[ inline]
189
189
pub fn insert ( & mut self , elem : T ) -> bool {
190
- assert ! (
190
+ debug_assert ! (
191
191
elem. index( ) < self . domain_size,
192
192
"inserting element at index {} but domain size is {}" ,
193
193
elem. index( ) ,
194
194
self . domain_size,
195
195
) ;
196
196
let ( word_index, mask) = word_index_and_mask ( elem) ;
197
- let word_ref = & mut self . words [ word_index] ;
197
+ // SAFETY:
198
+ // The number of words we have is the domain size divided by word size (rounded up). We have
199
+ // asserted above that the element is contained within the domain size. Therefore,
200
+ // word_index is in bounds.
201
+ let word_ref = unsafe { self . words . get_unchecked_mut ( word_index) } ;
198
202
let word = * word_ref;
199
203
let new_word = word | mask;
200
204
* word_ref = new_word;
You can’t perform that action at this time.
0 commit comments