@@ -780,8 +780,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
780
780
// - there are no DELETED entries.
781
781
// - we know there is enough space in the table.
782
782
// - all elements are unique.
783
- let index = new_table. find_insert_slot ( hash) ;
784
- new_table. set_ctrl_h2 ( index, hash) ;
783
+ let index = new_table. prepare_insert_slot ( hash) ;
785
784
new_table. bucket ( index) . copy_from_nonoverlapping ( & item) ;
786
785
}
787
786
@@ -863,15 +862,14 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
863
862
#[ cfg( any( feature = "raw" , feature = "rustc-internal-api" ) ) ]
864
863
pub fn insert_no_grow ( & mut self , hash : u64 , value : T ) -> Bucket < T > {
865
864
unsafe {
866
- let index = self . table . find_insert_slot ( hash) ;
865
+ let index = self . table . prepare_insert_slot ( hash) ;
867
866
let bucket = self . table . bucket ( index) ;
868
867
869
868
// If we are replacing a DELETED entry then we don't need to update
870
869
// the load counter.
871
870
let old_ctrl = * self . table . ctrl ( index) ;
872
871
self . table . growth_left -= special_is_empty ( old_ctrl) as usize ;
873
872
874
- self . table . set_ctrl_h2 ( index, hash) ;
875
873
bucket. write ( value) ;
876
874
self . table . items += 1 ;
877
875
bucket
@@ -1124,6 +1122,17 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1124
1122
}
1125
1123
}
1126
1124
1125
+ /// Searches for an empty or deleted bucket which is suitable for inserting
1126
+ /// a new element and sets the hash for that slot.
1127
+ ///
1128
+ /// There must be at least 1 empty bucket in the table.
1129
+ #[ inline]
1130
+ unsafe fn prepare_insert_slot ( & self , hash : u64 ) -> usize {
1131
+ let index = self . find_insert_slot ( hash) ;
1132
+ self . set_ctrl_h2 ( index, hash) ;
1133
+ index
1134
+ }
1135
+
1127
1136
/// Searches for an empty or deleted bucket which is suitable for inserting
1128
1137
/// a new element.
1129
1138
///
@@ -1583,8 +1592,7 @@ impl<T: Clone, A: Allocator + Clone> RawTable<T, A> {
1583
1592
// - there are no DELETED entries.
1584
1593
// - we know there is enough space in the table.
1585
1594
// - all elements are unique.
1586
- let index = guard_self. table . find_insert_slot ( hash) ;
1587
- guard_self. table . set_ctrl_h2 ( index, hash) ;
1595
+ let index = guard_self. table . prepare_insert_slot ( hash) ;
1588
1596
guard_self. bucket ( index) . write ( item) ;
1589
1597
}
1590
1598
}
0 commit comments