Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp275660pxb; Wed, 25 Aug 2021 03:01:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt6Z/mUy7yGUDbSxb2xhYZXVi38U5LAXgP1+Rd64YlVzjnRZN4Ud7THp+4sDoedfXwJzH+ X-Received: by 2002:a17:906:1382:: with SMTP id f2mr37789218ejc.536.1629885700928; Wed, 25 Aug 2021 03:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629885700; cv=none; d=google.com; s=arc-20160816; b=Rn26/DJZJLoErFuIa9sihKL/ImRwAXOvOjXm6nSsCvi5+sfogriwjP45GZcqlCR+gI rMf+kXVjg0e+B0+l/2G6s6s+3nsv2YqtOBhDizuburtO4bMBL6xh/qPfZUZez9R9uEPo 9Jf35HwIqoxCsv5lemvTNrkISGwkufZ3BjazWccLjZXd7dUKZAcygY6do8h354mYsgrx Dh9wuMgpoyEG7I3yRyMTudNoo1S8rikgloAu2rOlOYSLj9UDQE3J3Poa4UgtqGoNVVGu nsMdFmw2ntzUVF4e7J/jDOz/D4j3ZJp/FCplPfLw18YVO62rByiWSsv2nsCimbbtthGE 455Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from; bh=3mQURWiRFijyZWlgD3XnT3HM930+1C9tKBdUPLym3L0=; b=opCkDuH2+13CPy435cmeI/Xf7XWZDs47ZbGH/i9etPdjo8PUM6ash2YvCZH/73cUP/ rtJkrcjvPEaQoyTmhCTjdUJVOcVNWm/LXL9EFw1uroQsGzCF6h7zKbmeQ9C5nsmpv32c 0hBG1jCieyoliVpEzdzQYgWQSdaf821POmPmFGffL8JElBbuEFRaPC+/979lZb8aN8io 0pAHKUYAZHMFNqVCav66spU6UhWrFrqpGyLB1R1QvNomMFOH8qpyyYwvHsb6DTnZ9vKG nWFHlidD8cpfpRsA95P3Hzq00Neenp4UJkHYwsdgOIIlVWTEhDfhX2VAInAFFFtZfFzv KwpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq3si25197745ejc.142.2021.08.25.03.01.18; Wed, 25 Aug 2021 03:01:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237163AbhHYKAk (ORCPT + 99 others); Wed, 25 Aug 2021 06:00:40 -0400 Received: from mx316.baidu.com ([180.101.52.236]:17311 "EHLO njjs-sys-mailin05.njjs.baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237077AbhHYKAj (ORCPT ); Wed, 25 Aug 2021 06:00:39 -0400 Received: from bjhw-sys-rpm015653cc5.bjhw.baidu.com (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by njjs-sys-mailin05.njjs.baidu.com (Postfix) with ESMTP id 01996CF8003A; Wed, 25 Aug 2021 17:59:49 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by bjhw-sys-rpm015653cc5.bjhw.baidu.com (Postfix) with ESMTP id CFBF0D9932; Wed, 25 Aug 2021 17:59:48 +0800 (CST) From: Li RongQing To: peterz@infradead.org, dbueso@suse.de, mingo@kernel.org, michel@lespinasse.org, linux-kernel@vger.kernel.org, lirongqing@baidu.com Subject: [PATCH] rbtree: stop iteration early in rb_find_first Date: Wed, 25 Aug 2021 17:59:48 +0800 Message-Id: <1629885588-10590-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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