Skip to content

Commit

Permalink
Merge pull request #6 from emilHof/stack-borrow-nonnull
Browse files Browse the repository at this point in the history
fix clippy lint by dereferencing ptr explicitly before swapping mem
  • Loading branch information
emilHof committed Dec 12, 2022
2 parents 78a87aa + b1d858a commit e0db0f2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib.rs
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 e0db0f2

Please sign in to comment.