From 3bf0243a55263002cc154fb1b4e40daf014d2a07 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Sat, 2 Nov 2024 17:58:08 -0500 Subject: [PATCH] refactor: have Index::next_key avoid cloning Arc --- nomt/src/beatree/index.rs | 6 +++--- nomt/src/beatree/ops/update/branch_stage.rs | 2 +- nomt/src/beatree/ops/update/leaf_stage.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nomt/src/beatree/index.rs b/nomt/src/beatree/index.rs index 33217da0d0..52328cb1e6 100644 --- a/nomt/src/beatree/index.rs +++ b/nomt/src/beatree/index.rs @@ -23,12 +23,12 @@ impl Index { self.first_key_map.get_prev(&key).map(|(sep, b)| (sep.clone(), b.clone())) } - /// Get the first branch with separator greater than the given key. - pub fn next_after(&self, key: Key) -> Option<(Key, Arc)> { + /// Get the first separator greater than the given key. + pub fn next_key(&self, key: Key) -> Option { self.first_key_map .range(RangeFromExclusive { start: key }) .next() - .map(|(k, b)| (*k, b.clone())) + .map(|(k, _)| *k) } /// Remove the branch with the given separator key. diff --git a/nomt/src/beatree/ops/update/branch_stage.rs b/nomt/src/beatree/ops/update/branch_stage.rs index 7dd03301d4..1b3b3f74f2 100644 --- a/nomt/src/beatree/ops/update/branch_stage.rs +++ b/nomt/src/beatree/ops/update/branch_stage.rs @@ -262,7 +262,7 @@ fn reset_branch_base_fresh( return; }; - let cutoff = bbn_index.next_after(key).map(|(k, _)| k); + let cutoff = bbn_index.next_key(key); branches_tracker.delete(separator, branch.bbn_pn().into(), cutoff); diff --git a/nomt/src/beatree/ops/update/leaf_stage.rs b/nomt/src/beatree/ops/update/leaf_stage.rs index 802e101bbd..997e4fe482 100644 --- a/nomt/src/beatree/ops/update/leaf_stage.rs +++ b/nomt/src/beatree/ops/update/leaf_stage.rs @@ -43,7 +43,7 @@ fn indexed_leaf(bbn_index: &Index, key: Key) -> Option<(Key, Option, PageNu let cutoff = if i + 1 < branch.n() as usize { Some(get_key(&branch, i + 1)) } else { - bbn_index.next_after(key).map(|(cutoff, _)| cutoff) + bbn_index.next_key(key) }; Some((separator, cutoff, leaf_pn))