From: Michel Lespinasse <michel@lespinasse.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Li RongQing <lirongqing@baidu.com>,
dbueso@suse.de, mingo@kernel.org, michel@lespinasse.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rbtree: stop iteration early in rb_find_first
Date: Wed, 25 Aug 2021 04:53:32 -0700 [thread overview]
Message-ID: <20210825115332.GA4645@lespinasse.org> (raw)
In-Reply-To: <YSYr7nqql825rHol@hirez.programming.kicks-ass.net>
On Wed, Aug 25, 2021 at 01:39:26PM +0200, Peter Zijlstra wrote:
> On Wed, Aug 25, 2021 at 05:59:48PM +0800, Li RongQing wrote:
> > 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;
>
> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
NAK. This looked slightly wrong before, and is more wrong after.
Before:
there was this weird condition if (c <= 0) {} else if (c > 0) {} ,
making you wonder what the third possibility may be. Easy fix would be
to remove the second condition.
After:
say the key is equal the root, so the code sets match=root and goes left.
Then it stops searching because match is set and c<0.
This doesn't work, the code needs to keep searching for the leftmost match.
--
Michel "walken" Lespinasse
next prev parent reply other threads:[~2021-08-25 11:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210825115332.GA4645@lespinasse.org \
--to=michel@lespinasse.org \
--cc=dbueso@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=lirongqing@baidu.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.