Skip to content

Commit 026254c

Browse files
committed
refactor: eliminate redundant get_leaf_mut call in leaf split
- Use else-if structure to avoid duplicate arena lookup - Single get_leaf_mut(leaf_id) call now handles both linked list update and insertion - Maintains same functionality with better performance - Properly handles key/value ownership without cloning
1 parent 687783d commit 026254c

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

rust/src/insert_operations.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,15 @@ impl<K: Ord + Clone, V: Clone> BPlusTreeMap<K, V> {
9090
// Update the linked list first
9191
if let Some(leaf) = self.get_leaf_mut(leaf_id) {
9292
leaf.next = new_right_id;
93-
}
94-
95-
// Then insert into the correct node
96-
if index <= leaf_keys_len {
97-
// Insert into the original (left) leaf
98-
if let Some(leaf) = self.get_leaf_mut(leaf_id) {
93+
// Then insert into the correct node
94+
if index <= leaf_keys_len {
95+
// Insert into the original (left) leaf
9996
leaf.insert_at_index(index, key, value);
100-
}
101-
} else {
102-
// Insert into the new (right) leaf
103-
if let Some(new_right) = self.get_leaf_mut(new_right_id) {
104-
new_right.insert_at_index(index - leaf_keys_len, key, value);
97+
} else {
98+
// Insert into the new (right) leaf
99+
if let Some(new_right) = self.get_leaf_mut(new_right_id) {
100+
new_right.insert_at_index(index - leaf_keys_len, key, value);
101+
}
105102
}
106103
}
107104

0 commit comments

Comments
 (0)