File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -829,18 +829,21 @@ impl<T> RawTable<T> {
829
829
pub fn insert ( & mut self , hash : u64 , value : T , hasher : impl Fn ( & T ) -> u64 ) -> Bucket < T > {
830
830
unsafe {
831
831
let mut index = self . find_insert_slot ( hash) ;
832
+
833
+ // We can avoid growing the table once we have reached our load
834
+ // factor if we are replacing a tombstone. This works since the
835
+ // number of EMPTY slots does not change in this case.
832
836
let old_ctrl = * self . ctrl ( index) ;
833
- if self . growth_left == 0 && special_is_empty ( old_ctrl) {
837
+ if unlikely ( self . growth_left == 0 && special_is_empty ( old_ctrl) ) {
834
838
self . reserve ( 1 , hasher) ;
835
839
index = self . find_insert_slot ( hash) ;
836
- self . growth_left -= 1 ;
837
- } else {
838
- self . growth_left -= special_is_empty ( old_ctrl) as usize
839
840
}
840
- self . items += 1 ;
841
- self . set_ctrl ( index, h2 ( hash) ) ;
841
+
842
842
let bucket = self . bucket ( index) ;
843
+ self . growth_left -= special_is_empty ( old_ctrl) as usize ;
844
+ self . set_ctrl ( index, h2 ( hash) ) ;
843
845
bucket. write ( value) ;
846
+ self . items += 1 ;
844
847
bucket
845
848
}
846
849
}
@@ -851,6 +854,7 @@ impl<T> RawTable<T> {
851
854
///
852
855
/// This does not check if the given element already exists in the table.
853
856
#[ inline]
857
+ #[ cfg( feature = "rustc-internal-api" ) ]
854
858
pub fn insert_no_grow ( & mut self , hash : u64 , value : T ) -> Bucket < T > {
855
859
unsafe {
856
860
let index = self . find_insert_slot ( hash) ;
You can’t perform that action at this time.
0 commit comments