diff --git a/agb-hashmap/src/lib.rs b/agb-hashmap/src/lib.rs index 4251768e..8e167df2 100644 --- a/agb-hashmap/src/lib.rs +++ b/agb-hashmap/src/lib.rs @@ -350,9 +350,12 @@ where { let hash = self.hash(key); - self.nodes - .location(key, hash) - .and_then(|location| self.nodes.node_at(location).key_value_ref()) + let location = self.nodes.location(key, hash)?; + Some(unsafe { + self.nodes + .node_at_unchecked(location) + .key_value_ref_unchecked() + }) } /// Returns a reference to the value corresponding to the key. Returns [`None`] if there is diff --git a/agb-hashmap/src/node.rs b/agb-hashmap/src/node.rs index eb4ce42b..dc96ceba 100644 --- a/agb-hashmap/src/node.rs +++ b/agb-hashmap/src/node.rs @@ -66,12 +66,8 @@ impl Node { } } - pub(crate) fn key_value_ref(&self) -> Option<(&K, &V)> { - if self.has_value() { - Some(unsafe { (self.key.assume_init_ref(), self.value.assume_init_ref()) }) - } else { - None - } + pub(crate) unsafe fn key_value_ref_unchecked(&self) -> (&K, &V) { + (self.key.assume_init_ref(), self.value.assume_init_ref()) } pub(crate) fn key_value_mut(&mut self) -> Option<(&K, &mut V)> {