[PATCH v3] rust_binder: speed up get_node_debug_info using lower_bound iter
Rafael Passos <[email protected]>
| Newsgroups | org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
Finding the next node in the RBTree can be done more efficiently using the cursor_lower_bound, as it reduces cost from O(n) to O(log n). Reviewed-by: Alice Ryhl <[email protected]> Link: https://github.com/Rust-for-Linux/linux/issues/1249 Suggested-by: Alice Ryhl <[email protected]> Signed-off-by: Rafael Passos <[email protected]> --- V1: https://lore.kernel.org/rust-for-linux/[email protected]/ Changes from V1: - remove the "if/else" block checking if the current>prt. The cursor_lower_bound function returns the "key" or the next larger. This is indeed better, my check was unnecessary. - add a comment about this fact before the cursor_lower_bound V2: https://lore.kernel.org/rust-for-linux/[email protected]/ Changes from V2: - formatting fixes with rustfmt drivers/android/binder/process.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs index cdd1a9079726..b74c26f041bf 100644 --- a/drivers/android/binder/process.rs +++ b/drivers/android/binder/process.rs @@ -1174,11 +1174,10 @@ fn get_node_debug_info(&self, data: UserSlice) -> Result { { let inner = self.inner.lock(); - for (node_ptr, node) in &inner.nodes { - if *node_ptr > ptr { - node.populate_debug_info(&mut out, &inner); - break; - } + // cursor_lower_bound retrieves the "key" passed or the next existing larger key + if let Some(cursor) = inner.nodes.cursor_lower_bound(&(ptr + 1)) { + let (_, node) = cursor.current(); + node.populate_debug_info(&mut out, &inner); } } -- 2.55.0