@@ -689,28 +689,15 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
689
689
& |table, index| hasher ( table. bucket :: < T > ( index) . as_ref ( ) ) ,
690
690
fallibility,
691
691
TableLayout :: new :: < T > ( ) ,
692
- mem:: transmute ( ptr:: drop_in_place :: < T > as unsafe fn ( * mut T ) ) ,
693
- mem:: needs_drop :: < T > ( ) ,
692
+ if mem:: needs_drop :: < T > ( ) {
693
+ Some ( mem:: transmute ( ptr:: drop_in_place :: < T > as unsafe fn ( * mut T ) ) )
694
+ } else {
695
+ None
696
+ } ,
694
697
)
695
698
}
696
699
}
697
700
698
- /// Rehashes the contents of the table in place (i.e. without changing the
699
- /// allocation).
700
- ///
701
- /// If `hasher` panics then some the table's contents may be lost.
702
- #[ cfg( test) ]
703
- fn rehash_in_place ( & mut self , hasher : impl Fn ( & T ) -> u64 ) {
704
- unsafe {
705
- self . table . rehash_in_place (
706
- & |table, index| hasher ( table. bucket :: < T > ( index) . as_ref ( ) ) ,
707
- mem:: size_of :: < T > ( ) ,
708
- mem:: transmute ( ptr:: drop_in_place :: < T > as unsafe fn ( * mut T ) ) ,
709
- mem:: needs_drop :: < T > ( ) ,
710
- ) ;
711
- }
712
- }
713
-
714
701
/// Allocates a new table of a different size and moves the contents of the
715
702
/// current table into it.
716
703
fn resize (
@@ -1389,8 +1376,7 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1389
1376
hasher : & dyn Fn ( & mut Self , usize ) -> u64 ,
1390
1377
fallibility : Fallibility ,
1391
1378
layout : TableLayout ,
1392
- drop : fn ( * mut u8 ) ,
1393
- drops : bool ,
1379
+ drop : Option < fn ( * mut u8 ) > ,
1394
1380
) -> Result < ( ) , TryReserveError > {
1395
1381
// Avoid `Option::ok_or_else` because it bloats LLVM IR.
1396
1382
let new_items = match self . items . checked_add ( additional) {
@@ -1401,7 +1387,7 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1401
1387
if new_items <= full_capacity / 2 {
1402
1388
// Rehash in-place without re-allocating if we have plenty of spare
1403
1389
// capacity that is locked up due to DELETED entries.
1404
- self . rehash_in_place ( hasher, layout. size , drop, drops ) ;
1390
+ self . rehash_in_place ( hasher, layout. size , drop) ;
1405
1391
Ok ( ( ) )
1406
1392
} else {
1407
1393
// Otherwise, conservatively resize to at least the next size up
@@ -1475,8 +1461,7 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1475
1461
& mut self ,
1476
1462
hasher : & dyn Fn ( & mut Self , usize ) -> u64 ,
1477
1463
size_of : usize ,
1478
- drop : fn ( * mut u8 ) ,
1479
- drops : bool ,
1464
+ drop : Option < fn ( * mut u8 ) > ,
1480
1465
) {
1481
1466
// If the hash function panics then properly clean up any elements
1482
1467
// that we haven't rehashed yet. We unfortunately can't preserve the
@@ -1485,7 +1470,7 @@ impl<A: Allocator + Clone> RawTableInner<A> {
1485
1470
self . prepare_rehash_in_place ( ) ;
1486
1471
1487
1472
let mut guard = guard ( self , move |self_| {
1488
- if drops {
1473
+ if let Some ( drop ) = drop {
1489
1474
for i in 0 ..self_. buckets ( ) {
1490
1475
if * self_. ctrl ( i) == DELETED {
1491
1476
self_. set_ctrl ( i, EMPTY ) ;
@@ -2375,6 +2360,20 @@ impl<'a, A: Allocator + Clone> Iterator for RawIterHashInner<'a, A> {
2375
2360
mod test_map {
2376
2361
use super :: * ;
2377
2362
2363
+ fn rehash_in_place < T > ( table : & mut RawTable < T > , hasher : impl Fn ( & T ) -> u64 ) {
2364
+ unsafe {
2365
+ table. table . rehash_in_place (
2366
+ & |table, index| hasher ( table. bucket :: < T > ( index) . as_ref ( ) ) ,
2367
+ mem:: size_of :: < T > ( ) ,
2368
+ if mem:: needs_drop :: < T > ( ) {
2369
+ Some ( mem:: transmute ( ptr:: drop_in_place :: < T > as unsafe fn ( * mut T ) ) )
2370
+ } else {
2371
+ None
2372
+ } ,
2373
+ ) ;
2374
+ }
2375
+ }
2376
+
2378
2377
#[ test]
2379
2378
fn rehash ( ) {
2380
2379
let mut table = RawTable :: new ( ) ;
@@ -2390,7 +2389,7 @@ mod test_map {
2390
2389
assert ! ( table. find( i + 100 , |x| * x == i + 100 ) . is_none( ) ) ;
2391
2390
}
2392
2391
2393
- table . rehash_in_place ( hasher) ;
2392
+ rehash_in_place ( & mut table , hasher) ;
2394
2393
2395
2394
for i in 0 ..100 {
2396
2395
unsafe {
0 commit comments