Skip to content

Commit

Permalink
fix clippy lint by dereferencing ptr explicitly before swapping mem
Browse files Browse the repository at this point in the history
  • Loading branch information
emilHof committed Dec 12, 2022
1 parent 133f76b commit b1d858a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,15 @@ impl<K: Hash + Eq, V, S: BuildHasher> LruCache<K, V, S> {

match node_ref {
Some(node_ref) => {
let node_ptr: *mut LruEntry<K, V> = node_ref.as_ptr();

// if the key is already in the cache just update its value and move it to the
// front of the list
unsafe { mem::swap(&mut v, &mut *(*node_ptr).val.as_mut_ptr()) }
let node_ptr: *mut LruEntry<K, V> = node_ref.as_ptr();

// gets a reference to the node to perform a swap and drops it right after
let node_ref = unsafe { &mut (*(*node_ptr).val.as_mut_ptr()) };
mem::swap(&mut v, node_ref);
let _ = node_ref;

self.detach(node_ptr);
self.attach(node_ptr);
Some((k, v))
Expand Down

0 comments on commit b1d858a

Please sign in to comment.