linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rbtree: stop iteration early in rb_find_first
@ 2021-08-25  9:59 Li RongQing
  2021-08-25 11:39 ` Peter Zijlstra
  0 siblings, 1 reply; 13+ messages in thread
From: Li RongQing @ 2021-08-25  9:59 UTC (permalink / raw)
  To: peterz, dbueso, mingo, michel, linux-kernel, lirongqing

stop iteration if match is not NULL and result of cmp is
not zero, this means the matched node has been found, and
the node with same key has been passed

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 include/linux/rbtree.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
index d31ecaf4fdd3..2689771df9bb 100644
--- a/include/linux/rbtree.h
+++ b/include/linux/rbtree.h
@@ -324,6 +324,9 @@ rb_find_first(const void *key, const struct rb_root *tree,
 		} else if (c > 0) {
 			node = node->rb_right;
 		}
+
+		if (match && c)
+			break;
 	}
 
 	return match;
-- 
2.33.0.69.gc420321.dirty


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-08-26  5:04 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25  9:59 [PATCH] rbtree: stop iteration early in rb_find_first Li RongQing
2021-08-25 11:39 ` Peter Zijlstra
2021-08-25 11:53   ` Michel Lespinasse
2021-08-25 11:58     ` Michel Lespinasse
2021-08-25 12:31       ` Peter Zijlstra
2021-08-25 13:21       ` Peter Zijlstra
2021-08-25 16:08         ` 答复: " Li,Rongqing
     [not found]         ` <90ea3457ddc7485fbc8db5f7ca5b07ab@baidu.com>
2021-08-25 17:18           ` Peter Zijlstra
2021-08-25 18:26             ` 答复: " Li,Rongqing
2021-08-25 19:20               ` Peter Zijlstra
2021-08-26  5:03                 ` 答复: " Li,Rongqing
2021-08-25 12:29     ` Peter Zijlstra
2021-08-25 12:32       ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).