rust: add fast path to `RBTree::find_mut` for empty tree
Onur Özkan
reviewerPATCH 1/1 rust: add fast path to `RBTree::find_mut` for empty tree
Adds a fast path to RBTree::find_mut that immediately returns None when the tree is empty.
This should also benefit RBTree::get_mut, RBTree::remove_node and RBTree::remove functions as they rely on find_mut internally.
Signed-off-by Onur Özkan <[email protected]>
--- rust/kernel/rbtree.rs | 5 +++++ 1 file changed, 5 insertions(+)
rust/kernel/rbtree.rs +5 -0
@@ -365,6 +365,11 @@ pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {/// Used for accessing the given node, if it exists. pub fn find_mut (&mut self, key: &K ) ->Option <OccupiedEntry <'_,K ,V >> { +// Fast path: return `None` when tree is empty. +if self.root.rb_node.is_null () { +return None ; + } +match self.raw_entry (key) {RawEntry ::Occupied (entry) =>Some (entry),RawEntry ::Vacant (_entry) =>None ,
--
2.50.0
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · Onur Özkan
Oops, I didn't realize that
rb_nodewas a pointer. Please don't take the patch seriously. :)
I think this reply didn't reach the lists because it uses HTML.
Cheers,
Miguel