summaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorOnur Özkan <work@onurozkan.dev>2025-07-08 10:58:50 +0300
committerMiguel Ojeda <ojeda@kernel.org>2025-07-14 23:53:35 +0200
commitb6f885060e8e24f1a1a9205ba41a0524964e8c30 (patch)
tree8537883f621f26eaefcd339aa76cc5e7069f9131 /rust/kernel
parent8ffb945647f8740e2eab81ace8c87f9734c85f95 (diff)
rust: rbtree: simplify finding `current` in `remove_current`
The previous version used a verbose `match` to get `current`, which may be slightly confusing at first glance. This change makes it shorter and more clearly expresses the intent: prefer `next` if available, otherwise fall back to `prev`. Signed-off-by: Onur Özkan <work@onurozkan.dev> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://lore.kernel.org/r/20250708075850.25789-1-work@onurozkan.dev Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/rbtree.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/rust/kernel/rbtree.rs b/rust/kernel/rbtree.rs
index 9457134eb3af..b8fe6be6fcc4 100644
--- a/rust/kernel/rbtree.rs
+++ b/rust/kernel/rbtree.rs
@@ -775,23 +775,14 @@ impl<'a, K, V> Cursor<'a, K, V> {
// the tree cannot change. By the tree invariant, all nodes are valid.
unsafe { bindings::rb_erase(&mut (*this).links, addr_of_mut!(self.tree.root)) };
- let current = match (prev, next) {
- (_, Some(next)) => next,
- (Some(prev), None) => prev,
- (None, None) => {
- return (None, node);
- }
- };
+ // INVARIANT:
+ // - `current` is a valid node in the [`RBTree`] pointed to by `self.tree`.
+ let cursor = next.or(prev).map(|current| Self {
+ current,
+ tree: self.tree,
+ });
- (
- // INVARIANT:
- // - `current` is a valid node in the [`RBTree`] pointed to by `self.tree`.
- Some(Self {
- current,
- tree: self.tree,
- }),
- node,
- )
+ (cursor, node)
}
/// Remove the previous node, returning it if it exists.