@@ -169,47 +169,56 @@
}
/// Number of live entries.
+ #[inline]
pub fn len(&self) -> usize {
self.map.len()
}
/// True if there are no live entries.
+ #[inline]
pub fn is_empty(&self) -> bool {
self.map.is_empty()
}
/// True if `k` is present.
+ #[inline]
pub fn contains_key(&self, k: &K) -> bool {
self.map.contains_key(k)
}
/// Look up a value by key.
+ #[inline]
pub fn get(&self, k: &K) -> Option<&V> {
self.map.get(k)
}
/// Look up a (key, value) pair by insertion index.
+ #[inline]
pub fn get_index(&self, idx: usize) -> Option<(&K, &V)> {
self.map.get_index(idx)
}
/// Iterate entries in insertion order.
+ #[inline]
pub fn iter(&self) -> indexmap::map::Iter<'_, K, V> {
self.map.iter()
}
/// Iterate keys in insertion order.
+ #[inline]
pub fn keys(&self) -> indexmap::map::Keys<'_, K, V> {
self.map.keys()
}
/// Iterate values in insertion order.
+ #[inline]
pub fn values(&self) -> indexmap::map::Values<'_, K, V> {
self.map.values()
}
/// Borrow the underlying [`IndexMap`] read-only. All mutations must go
/// through the store API so the log stays in sync.
+ #[inline]
pub fn as_indexmap(&self) -> &IndexMap<K, V> {
&self.map
}
@@ -217,6 +226,7 @@
/// Insert `k -> v`, returning the previous value if any. If `k` already
/// existed the entry keeps its insertion position (standard
/// [`IndexMap::insert`] semantics).
+ #[inline]
pub fn insert(&mut self, k: K, v: V) -> io::Result<Option<V>> {
self.scratch.clear();
self.scratch.extend_from_slice(&[0u8; LEN_BYTES]);
@@ -234,6 +244,7 @@
/// Remove the entry for `k` (shift-remove — preserves the order of the
/// remaining entries). Returns the previous value if any.
+ #[inline]
pub fn remove(&mut self, k: &K) -> io::Result<Option<V>> {
if !self.map.contains_key(k) {
return Ok(None);
@@ -255,6 +266,7 @@
/// Edit the value for `k` in place via a closure. The post-edit value is
/// appended to the log as a fresh `Insert` record, so the change survives
/// a restart. Returns `None` if `k` is absent, else `Some(f's return)`.
+ #[inline]
pub fn modify<F, R>(&mut self, k: &K, f: F) -> io::Result<Option<R>>
where
F: FnOnce(&mut V) -> R,
@@ -321,6 +333,7 @@
Ok(())
}
+ #[inline]
fn flush_scratch(&mut self) -> io::Result<()> {
// Callers reserve LEN_BYTES at the front of `scratch`; fill the length
// in place so the length-prefix and payload land in a single write.
@@ -335,6 +348,7 @@
Ok(())
}
+ #[inline]
fn maybe_compact(&mut self) -> io::Result<()> {
if self.log_bytes < self.cfg.min_compact_bytes {
return Ok(());
@@ -356,6 +370,7 @@
}
}
+#[inline]
fn serialize_err(e: bincode::Error) -> io::Error {
io::Error::new(ErrorKind::InvalidData, e)
}