@@ -501,7 +501,7 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> Cache<K, V> for RawLRU
501
501
{
502
502
match self . map . get_mut ( KeyWrapper :: from_ref ( k) ) {
503
503
None => None ,
504
- Some ( node) => Some ( unsafe { & mut * node. as_mut ( ) . val . as_mut_ptr ( ) } ) ,
504
+ Some ( node) => Some ( unsafe { & mut * ( * node. as_ptr ( ) ) . val . as_mut_ptr ( ) } ) ,
505
505
}
506
506
}
507
507
@@ -557,10 +557,10 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> Cache<K, V> for RawLRU
557
557
Some ( old_node) => unsafe {
558
558
let node_ptr = & mut * old_node. as_ptr ( ) ;
559
559
self . detach ( node_ptr) ;
560
- let node = * Box :: from_raw ( old_node. as_ptr ( ) ) ;
560
+ let mut node = * Box :: from_raw ( old_node. as_ptr ( ) ) ;
561
561
let val = node. val . assume_init ( ) ;
562
- self . cb ( & * node_ptr . key . as_ptr ( ) , & val) ;
563
- ptr:: drop_in_place ( node_ptr . key . as_mut_ptr ( ) ) ;
562
+ self . cb ( & * node . key . as_ptr ( ) , & val) ;
563
+ ptr:: drop_in_place ( node . key . assume_init_mut ( ) ) ;
564
564
Some ( val)
565
565
} ,
566
566
}
@@ -1363,7 +1363,7 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> RawLRU<K, V, E, S> {
1363
1363
{
1364
1364
match self . map . get_mut ( KeyWrapper :: from_ref ( k) ) {
1365
1365
None => None ,
1366
- Some ( node) => Some ( unsafe { & mut * node. as_mut ( ) . val . as_mut_ptr ( ) } ) ,
1366
+ Some ( node) => Some ( unsafe { & mut * ( * node. as_ptr ( ) ) . val . as_mut_ptr ( ) } ) ,
1367
1367
}
1368
1368
}
1369
1369
@@ -1375,7 +1375,7 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> RawLRU<K, V, E, S> {
1375
1375
{
1376
1376
self . map
1377
1377
. get ( KeyWrapper :: from_ref ( k) )
1378
- . map ( |node| unsafe { & * node. as_ref ( ) . val . as_ptr ( ) } )
1378
+ . map ( |node| unsafe { & * ( * node. as_ptr ( ) ) . val . as_ptr ( ) } )
1379
1379
}
1380
1380
1381
1381
// used for avoiding borrow checker issues
@@ -1414,22 +1414,22 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> RawLRU<K, V, E, S> {
1414
1414
}
1415
1415
}
1416
1416
1417
- pub ( crate ) fn put_nonnull ( & mut self , mut bks : NonNull < EntryNode < K , V > > ) -> PutResult < K , V > {
1417
+ // let old_key = KeyRef {
1418
+ // k: unsafe { &(*(*(*self.tail).prev).key.as_ptr()) },
1419
+ // };
1420
+ // let old_node = self.map.remove(&old_key).unwrap();
1421
+ pub ( crate ) fn put_nonnull ( & mut self , bks : NonNull < EntryNode < K , V > > ) -> PutResult < K , V > {
1418
1422
if self . len ( ) >= self . cap ( ) {
1419
1423
unsafe {
1420
1424
// Safety: the cache length is not zero, so the cache must have a tail node.
1421
- let node = ( ( * self . tail ) . prev ) . as_mut ( ) . unwrap ( ) ;
1422
- self . detach ( node ) ;
1423
-
1425
+ let old_key = KeyRef {
1426
+ k : & ( * ( * ( * self . tail ) . prev ) . key . as_ptr ( ) ) ,
1427
+ } ;
1424
1428
// Safety: the node is in cache, so the cache map must have the node.
1425
- let node = self
1426
- . map
1427
- . remove ( & KeyRef {
1428
- k : node. key . as_ptr ( ) ,
1429
- } )
1430
- . unwrap ( ) ;
1431
-
1432
- self . attach ( bks. as_mut ( ) ) ;
1429
+ let node = self . map . remove ( & old_key) . unwrap ( ) ;
1430
+ self . detach ( node. as_ptr ( ) ) ;
1431
+
1432
+ self . attach ( bks. as_ptr ( ) ) ;
1433
1433
self . map . insert (
1434
1434
KeyRef {
1435
1435
k : bks. as_ref ( ) . key . as_ptr ( ) ,
@@ -1464,23 +1464,19 @@ impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> RawLRU<K, V, E, S> {
1464
1464
1465
1465
pub ( crate ) fn put_or_evict_nonnull (
1466
1466
& mut self ,
1467
- mut bks : NonNull < EntryNode < K , V > > ,
1467
+ bks : NonNull < EntryNode < K , V > > ,
1468
1468
) -> Option < NonNull < EntryNode < K , V > > > {
1469
1469
if self . len ( ) >= self . cap ( ) {
1470
1470
unsafe {
1471
1471
// Safety: the cache length is not zero, so the cache must have a tail node.
1472
- let node = ( ( * self . tail ) . prev ) . as_mut ( ) . unwrap ( ) ;
1473
- self . detach ( node ) ;
1474
-
1472
+ let old_key = KeyRef {
1473
+ k : & ( * ( * ( * self . tail ) . prev ) . key . as_ptr ( ) ) ,
1474
+ } ;
1475
1475
// Safety: the node is in cache, so the cache map must have the node.
1476
- let node = self
1477
- . map
1478
- . remove ( & KeyRef {
1479
- k : node. key . as_ptr ( ) ,
1480
- } )
1481
- . unwrap ( ) ;
1482
-
1483
- self . attach ( bks. as_mut ( ) ) ;
1476
+ let node = self . map . remove ( & old_key) . unwrap ( ) ;
1477
+ self . detach ( node. as_ptr ( ) ) ;
1478
+
1479
+ self . attach ( bks. as_ptr ( ) ) ;
1484
1480
self . map . insert (
1485
1481
KeyRef {
1486
1482
k : bks. as_ref ( ) . key . as_ptr ( ) ,
0 commit comments