This commit is contained in:
Arsenii Kulikov
2025-12-24 03:00:24 +04:00
parent cf457689a6
commit 51932e35f5

View File

@@ -44,13 +44,6 @@ impl<'a, K, V> ForwardInMemoryCursor<'a, K, V> {
pub const fn reset(&mut self) { pub const fn reset(&mut self) {
self.idx = 0; self.idx = 0;
} }
#[inline]
fn next(&mut self) -> Option<&(K, V)> {
let entry = self.entries.get(self.idx)?;
self.idx += 1;
Some(entry)
}
} }
impl<K, V> ForwardInMemoryCursor<'_, K, V> impl<K, V> ForwardInMemoryCursor<'_, K, V>
@@ -76,16 +69,16 @@ where
/// Returns the first entry for which `predicate` returns `false` or `None`. The cursor will /// Returns the first entry for which `predicate` returns `false` or `None`. The cursor will
/// point to the returned entry. /// point to the returned entry.
fn advance_while(&mut self, predicate: impl Fn(&K) -> bool) -> Option<(K, V)> { fn advance_while(&mut self, predicate: impl Fn(&K) -> bool) -> Option<(K, V)> {
let mut entry; let remaining = &self.entries[self.idx..];
loop { if remaining.len() <= 32 {
entry = self.current(); while self.current().is_some_and(|(k, _)| predicate(k)) {
if entry.is_some_and(|(k, _)| predicate(k)) { self.idx += 1;
self.next();
} else {
break;
} }
} else {
let offset = remaining.partition_point(|(k, _)| predicate(k));
self.idx += offset;
} }
entry.cloned() self.current().cloned()
} }
} }