@@ -1166,7 +1166,7 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1166
1166
hash : u64 ,
1167
1167
eq : & mut dyn FnMut ( usize ) -> bool ,
1168
1168
) -> ( usize , bool ) {
1169
- let mut tombstone = None ;
1169
+ let mut insert_slot = None ;
1170
1170
1171
1171
let h2_hash = h2 ( hash) ;
1172
1172
let mut probe_seq = self . probe_seq ( hash) ;
@@ -1182,22 +1182,22 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1182
1182
}
1183
1183
}
1184
1184
1185
- let index = self . find_insert_slot_in_group ( & group, & probe_seq) ;
1185
+ // We didn't find the element we were looking for in the group, try to get an
1186
+ // insertion slot from the group if we don't have one yet.
1187
+ if likely ( insert_slot. is_none ( ) ) {
1188
+ insert_slot = self . find_insert_slot_in_group ( & group, & probe_seq) ;
1189
+ }
1186
1190
1187
- if likely ( index. is_some ( ) ) {
1188
- // Only stop the search if the group is empty. The element might be
1189
- // in a following group.
1190
- if likely ( group. match_empty ( ) . any_bit_set ( ) ) {
1191
- // Use a tombstone if we found one
1192
- return if unlikely ( tombstone. is_some ( ) ) {
1193
- ( tombstone. unwrap ( ) , false )
1194
- } else {
1195
- ( index. unwrap ( ) , false )
1196
- } ;
1197
- } else {
1198
- // We found a tombstone, record it so we can return it as a potential
1199
- // insertion location.
1200
- tombstone = index;
1191
+ // Only stop the search if the group contains at least one empty element.
1192
+ // Otherwise, the element that we are looking for might be in a following group.
1193
+ if likely ( group. match_empty ( ) . any_bit_set ( ) ) {
1194
+ // We must have found a insert slot by now, since the current group contains at
1195
+ // least one. For tables smaller than the group width, there will still be an
1196
+ // empty element in the current (and only) group due to the load factor.
1197
+ debug_assert ! ( insert_slot. is_some( ) ) ;
1198
+ match insert_slot {
1199
+ Some ( insert_slot) => return ( insert_slot, false ) ,
1200
+ None => unsafe { hint:: unreachable_unchecked ( ) } ,
1201
1201
}
1202
1202
}
1203
1203
0 commit comments