@@ -704,12 +704,20 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
704
704
// that we haven't rehashed yet. We unfortunately can't preserve the
705
705
// element since we lost their hash and have no way of recovering it
706
706
// without risking another panic.
707
- let mut guard = self . table . prepare_rehash_in_place (
708
- mem:: needs_drop :: < T > ( ) ,
709
- |self_ : & mut RawTableInner < A > , index| {
710
- self_. bucket :: < T > ( index) . drop ( ) ;
711
- } ,
712
- ) ;
707
+ self . table . prepare_rehash_in_place ( ) ;
708
+
709
+ let mut guard = guard ( & mut self . table , move |self_| {
710
+ if mem:: needs_drop :: < T > ( ) {
711
+ for i in 0 ..self_. buckets ( ) {
712
+ if * self_. ctrl ( i) == DELETED {
713
+ self_. set_ctrl ( i, EMPTY ) ;
714
+ self_. bucket :: < T > ( i) . drop ( ) ;
715
+ self_. items -= 1 ;
716
+ }
717
+ }
718
+ }
719
+ self_. growth_left = bucket_mask_to_capacity ( self_. bucket_mask ) - self_. items ;
720
+ } ) ;
713
721
714
722
// At this point, DELETED elements are elements that we haven't
715
723
// rehashed yet. Find them and re-insert them at their ideal
@@ -1170,16 +1178,9 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1170
1178
}
1171
1179
}
1172
1180
1173
- // We use `fn` argument here for `drop` as the function will only be called if the `hasher`
1174
- // panics which should be exceptionally rare. In return we only instantiate a single
1175
- // `prepare_rehash_in_place` per allocator (instead of per type and allocator)
1176
1181
#[ allow( clippy:: mut_mut) ]
1177
1182
#[ inline]
1178
- unsafe fn prepare_rehash_in_place < ' s > (
1179
- & ' s mut self ,
1180
- needs_drop : bool ,
1181
- drop : fn ( & mut Self , usize ) ,
1182
- ) -> crate :: scopeguard:: ScopeGuard < & mut Self , impl FnMut ( & mut & ' s mut Self ) + ' s > {
1183
+ unsafe fn prepare_rehash_in_place ( & mut self ) {
1183
1184
// Bulk convert all full control bytes to DELETED, and all DELETED
1184
1185
// control bytes to EMPTY. This effectively frees up all buckets
1185
1186
// containing a DELETED entry.
@@ -1198,18 +1199,6 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1198
1199
self . ctrl ( 0 )
1199
1200
. copy_to ( self . ctrl ( self . buckets ( ) ) , Group :: WIDTH ) ;
1200
1201
}
1201
- guard ( self , move |self_| {
1202
- if needs_drop {
1203
- for i in 0 ..self_. buckets ( ) {
1204
- if * self_. ctrl ( i) == DELETED {
1205
- self_. set_ctrl ( i, EMPTY ) ;
1206
- drop ( self_, i) ;
1207
- self_. items -= 1 ;
1208
- }
1209
- }
1210
- }
1211
- self_. growth_left = bucket_mask_to_capacity ( self_. bucket_mask ) - self_. items ;
1212
- } )
1213
1202
}
1214
1203
1215
1204
#[ cfg_attr( feature = "inline-more" , inline) ]
0 commit comments