Key value ref unchecked

This commit is contained in:
Gwilym Inzani 2023-05-09 21:37:20 +01:00
parent dc8589479e
commit 917163f88b
2 changed files with 8 additions and 9 deletions

View file

@ -350,9 +350,12 @@ where
{
let hash = self.hash(key);
let location = self.nodes.location(key, hash)?;
Some(unsafe {
self.nodes
.location(key, hash)
.and_then(|location| self.nodes.node_at(location).key_value_ref())
.node_at_unchecked(location)
.key_value_ref_unchecked()
})
}
/// Returns a reference to the value corresponding to the key. Returns [`None`] if there is

View file

@ -66,12 +66,8 @@ impl<K, V> Node<K, V> {
}
}
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)> {