Improve implementation of next

This commit is contained in:
Gwilym Inzani 2023-05-09 21:44:14 +01:00
parent b3e56e88f2
commit 68e68386a1
2 changed files with 10 additions and 10 deletions

View file

@ -471,9 +471,9 @@ impl<'a, K, V, ALLOCATOR: ClonableAllocator> Iterator for Iter<'a, K, V, ALLOCAT
let node = &self.map.nodes.node_at(self.at);
self.at += 1;
if node.has_value() {
if let Some(key_value) = node.key_value_ref() {
self.num_found += 1;
return Some((node.key_ref().unwrap(), node.value_ref().unwrap()));
return Some(key_value);
}
}
}

View file

@ -34,14 +34,6 @@ impl<K, V> Node<K, V> {
}
}
pub(crate) fn value_ref(&self) -> Option<&V> {
if self.has_value() {
Some(unsafe { self.value_ref_unchecked() })
} else {
None
}
}
pub(crate) unsafe fn value_ref_unchecked(&self) -> &V {
self.value.assume_init_ref()
}
@ -66,6 +58,14 @@ impl<K, V> Node<K, V> {
}
}
pub(crate) fn key_value_ref(&self) -> Option<(&K, &V)> {
if self.has_value() {
Some(unsafe { self.key_value_ref_unchecked() })
} else {
None
}
}
pub(crate) unsafe fn key_value_ref_unchecked(&self) -> (&K, &V) {
(self.key.assume_init_ref(), self.value.assume_init_ref())
}