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> {
187187 /// Insert `elem`. Returns whether the set has changed.
188188 #[ inline]
189189 pub fn insert ( & mut self , elem : T ) -> bool {
190- assert ! (
190+ debug_assert ! (
191191 elem. index( ) < self . domain_size,
192192 "inserting element at index {} but domain size is {}" ,
193193 elem. index( ) ,
194194 self . domain_size,
195195 ) ;
196196 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) } ;
198202 let word = * word_ref;
199203 let new_word = word | mask;
200204 * word_ref = new_word;
You can’t perform that action at this time.
0 commit comments