@@ -1225,11 +1225,7 @@ impl<A: Allocator + Clone> RawTableInner<A> {
12251225
12261226 /// Finds the position to insert something in a group.
12271227 #[ inline]
1228- unsafe fn find_insert_slot_in_group (
1229- & self ,
1230- group : & Group ,
1231- probe_seq : & ProbeSeq ,
1232- ) -> Option < usize > {
1228+ fn find_insert_slot_in_group ( & self , group : & Group , probe_seq : & ProbeSeq ) -> Option < usize > {
12331229 let bit = group. match_empty_or_deleted ( ) . lowest_set_bit ( ) ;
12341230
12351231 if likely ( bit. is_some ( ) ) {
@@ -1244,12 +1240,14 @@ impl<A: Allocator + Clone> RawTableInner<A> {
12441240 // table. This second scan is guaranteed to find an empty
12451241 // slot (due to the load factor) before hitting the trailing
12461242 // control bytes (containing EMPTY).
1247- if unlikely ( is_full ( * self . ctrl ( index) ) ) {
1248- debug_assert ! ( self . bucket_mask < Group :: WIDTH ) ;
1249- debug_assert_ne ! ( probe_seq. pos, 0 ) ;
1250- index = Group :: load_aligned ( self . ctrl ( 0 ) )
1251- . match_empty_or_deleted ( )
1252- . lowest_set_bit_nonzero ( ) ;
1243+ unsafe {
1244+ if unlikely ( is_full ( * self . ctrl ( index) ) ) {
1245+ debug_assert ! ( self . bucket_mask < Group :: WIDTH ) ;
1246+ debug_assert_ne ! ( probe_seq. pos, 0 ) ;
1247+ index = Group :: load_aligned ( self . ctrl ( 0 ) )
1248+ . match_empty_or_deleted ( )
1249+ . lowest_set_bit_nonzero ( ) ;
1250+ }
12531251 }
12541252
12551253 Some ( index)
@@ -1258,52 +1256,53 @@ impl<A: Allocator + Clone> RawTableInner<A> {
12581256 }
12591257 }
12601258
1261- /// Searches for an element in the table,
1262- /// or a potential slot where that element could be inserted.
1259+ /// Searches for an element in the table, or a potential slot where that element could be
1260+ /// inserted.
1261+ ///
1262+ /// This uses dynamic dispatch to reduce the amount of code generated, but that is
1263+ /// eliminated by LLVM optimizations.
12631264 #[ inline]
12641265 pub fn find_potential_inner (
12651266 & self ,
12661267 hash : u64 ,
12671268 eq : & mut dyn FnMut ( usize ) -> bool ,
12681269 ) -> ( usize , bool ) {
1269- unsafe {
1270- let mut tombstone = None ;
1270+ let mut tombstone = None ;
12711271
1272- let h2_hash = h2 ( hash) ;
1273- let mut probe_seq = self . probe_seq ( hash) ;
1272+ let h2_hash = h2 ( hash) ;
1273+ let mut probe_seq = self . probe_seq ( hash) ;
12741274
1275- loop {
1276- let group = Group :: load ( self . ctrl ( probe_seq. pos ) ) ;
1275+ loop {
1276+ let group = unsafe { Group :: load ( self . ctrl ( probe_seq. pos ) ) } ;
12771277
1278- for bit in group. match_byte ( h2_hash) . into_iter ( ) {
1279- let index = ( probe_seq. pos + bit) & self . bucket_mask ;
1278+ for bit in group. match_byte ( h2_hash) . into_iter ( ) {
1279+ let index = ( probe_seq. pos + bit) & self . bucket_mask ;
12801280
1281- if likely ( eq ( index) ) {
1282- return ( index, true ) ;
1283- }
1281+ if likely ( eq ( index) ) {
1282+ return ( index, true ) ;
12841283 }
1284+ }
12851285
1286- let index = self . find_insert_slot_in_group ( & group, & probe_seq) ;
1286+ let index = self . find_insert_slot_in_group ( & group, & probe_seq) ;
12871287
1288- if likely ( index. is_some ( ) ) {
1289- // Only stop the search if the group is empty. The element might be
1290- // in a following group.
1291- if likely ( group. match_empty ( ) . any_bit_set ( ) ) {
1292- // Use a tombstone if we found one
1293- return if unlikely ( tombstone. is_some ( ) ) {
1294- ( tombstone. unwrap ( ) , false )
1295- } else {
1296- ( index. unwrap ( ) , false )
1297- } ;
1288+ if likely ( index. is_some ( ) ) {
1289+ // Only stop the search if the group is empty. The element might be
1290+ // in a following group.
1291+ if likely ( group. match_empty ( ) . any_bit_set ( ) ) {
1292+ // Use a tombstone if we found one
1293+ return if unlikely ( tombstone. is_some ( ) ) {
1294+ ( tombstone. unwrap ( ) , false )
12981295 } else {
1299- // We found a tombstone, record it so we can return it as a potential
1300- // insertion location.
1301- tombstone = index;
1302- }
1296+ ( index. unwrap ( ) , false )
1297+ } ;
1298+ } else {
1299+ // We found a tombstone, record it so we can return it as a potential
1300+ // insertion location.
1301+ tombstone = index;
13031302 }
1304-
1305- probe_seq. move_next ( self . bucket_mask ) ;
13061303 }
1304+
1305+ probe_seq. move_next ( self . bucket_mask ) ;
13071306 }
13081307 }
13091308
0 commit comments