mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Improve implementation of next
This commit is contained in:
parent
b3e56e88f2
commit
68e68386a1
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue