From 3ae0e30d3c4f4d0cb20d3e596b1b70f47ab674ab Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 20 Mar 2022 13:42:28 +0000 Subject: [PATCH] Correctly drop key on override --- agb/src/hash_map.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/agb/src/hash_map.rs b/agb/src/hash_map.rs index dd5158b6..1d53cfa0 100644 --- a/agb/src/hash_map.rs +++ b/agb/src/hash_map.rs @@ -21,7 +21,7 @@ struct Node { } impl Node { - fn with_new_key_value(self, new_key: K, new_value: V) -> (Self, Option) { + fn with_new_key_value(mut self, new_key: K, new_value: V) -> (Self, Option) { ( Self { hash: self.hash, @@ -29,7 +29,7 @@ impl Node { key: MaybeUninit::new(new_key), value: MaybeUninit::new(new_value), }, - self.get_owned_value(), + self.take_key_value().map(|(_, v, _)| v), ) } @@ -67,17 +67,6 @@ impl Node { } } - fn get_owned_value(mut self) -> Option { - if self.has_value() { - let value = mem::replace(&mut self.value, MaybeUninit::uninit()); - self.distance_to_initial_bucket = -1; - - Some(unsafe { value.assume_init() }) - } else { - None - } - } - fn key_ref(&self) -> Option<&K> { if self.distance_to_initial_bucket >= 0 { Some(unsafe { self.key.assume_init_ref() })