From: David Sterba <dsterba@suse.cz>
To: Nikolay Borisov <nborisov@suse.com>
Cc: Qu Wenruo <quwenruo.btrfs@gmx.com>, WenRuo Qu <wqu@suse.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/3] btrfs: ctree: Reduce one indent level for btrfs_search_slot()
Date: Mon, 23 Sep 2019 18:09:55 +0200 [thread overview]
Message-ID: <20190923160955.GJ2751@twin.jikos.cz> (raw)
In-Reply-To: <04fc077c-3184-0ba8-9a12-c7b1fd08df7c@suse.com>
On Tue, Sep 10, 2019 at 11:42:47AM +0300, Nikolay Borisov wrote:
>
>
> On 10.09.19 г. 11:31 ч., Qu Wenruo wrote:
> >
> >
> > On 2019/9/10 下午4:24, Nikolay Borisov wrote:
> >>
> >>
> >> On 10.09.19 г. 10:40 ч., Qu Wenruo wrote:
> >>> In btrfs_search_slot(), we something like:
> >>>
> >>> if (level != 0) {
> >>> /* Do search inside tree nodes*/
> >>> } else {
> >>> /* Do search inside tree leaves */
> >>> goto done;
> >>> }
> >>>
> >>> This caused extra indent for tree node search code.
> >>> Change it to something like:
> >>>
> >>> if (level == 0) {
> >>> /* Do search inside tree leaves */
> >>> goto done'
> >>> }
> >>> /* Do search inside tree nodes */
> >>>
> >>> So we have more space to maneuver our code, this is especially useful as
> >>> the tree nodes search code is more complex than the leaves search code.
> >>>
> >>> Signed-off-by: Qu Wenruo <wqu@suse.com>
> >>
> >> I actually thing this patch makes comprehending the function worse.
> >
> > If the level == 0 lines is over 50 lines, maybe.
> >
> > But it's just 22 lines.
> >> Because the else is now somewhat implicit. E.g. one has to pay careful
> >> attention to the contents inside the first if and especially the
> >> unconditional 'goto done' to be able to understand the code after the
> >> 'if' construct.
> >
> > That's the same for the original code, you need to go a level upper to
> > see we're in level > 0 branch.
>
> But that's explicit with the 'if'
Well, I don't see a strong reason for one or another. I see your point
about the explicit 'if/else' for a condition that has two exclusive
options.
I looked at the code with the patch applied and regarding readability,
the if (level == 0) block is short enough to be seen at once and is an
'take a shortcut here'. The indentation level reduction improvement
seems justified to me.
next prev parent reply other threads:[~2019-09-23 16:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-10 7:40 [PATCH 0/3] Small code style cleanup for ctree.c Qu Wenruo
2019-09-10 7:40 ` [PATCH 1/3] btrfs: ctree: Reduce one indent level for btrfs_search_slot() Qu Wenruo
2019-09-10 7:54 ` Anand Jain
2019-09-10 8:24 ` Nikolay Borisov
2019-09-10 8:31 ` Qu Wenruo
2019-09-10 8:42 ` Nikolay Borisov
2019-09-23 16:09 ` David Sterba [this message]
2019-09-10 7:40 ` [PATCH 2/3] btrfs: ctree: Reduce one indent level for btrfs_search_old_slot() Qu Wenruo
2019-09-10 7:58 ` Anand Jain
2019-09-23 16:32 ` David Sterba
2019-09-10 7:40 ` [PATCH 3/3] btrfs: ctree: Remove stalled comment of setting up path lock Qu Wenruo
2019-09-10 7:51 ` Nikolay Borisov
2019-09-23 16:36 ` [PATCH 0/3] Small code style cleanup for ctree.c David Sterba
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=20190923160955.GJ2751@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.com \
--cc=quwenruo.btrfs@gmx.com \
--cc=wqu@suse.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox