mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: George Hu <integral@archlinux.org>, Chris Mason <clm@fb.com>,
	Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level()
Date: Sat, 28 Jun 2025 14:18:03 +0930	[thread overview]
Message-ID: <669773b7-4428-43ca-ab80-d7ed1c71886c@suse.com> (raw)
In-Reply-To: <20250628043235.29900-1-integral@archlinux.org>



在 2025/6/28 14:02, George Hu 写道:
> Refactor the btrfs_compress_set_level() function by replacing the
> nested usage of min() and max() macro with clamp() to simplify the
> code and improve readability.

Can you please only touch the "level != 0" branch using clamp()?

With a not-that-short expression used in the conditional operator, I do 
not think the final result is easier to read.

Thanks,
Qu

> 
> Signed-off-by: George Hu <integral@archlinux.org>
> ---
>   fs/btrfs/compression.c | 7 +------
>   1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index 48d07939fee4..662736d94814 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -972,12 +972,7 @@ static int btrfs_compress_set_level(unsigned int type, int level)
>   {
>   	const struct btrfs_compress_op *ops = btrfs_compress_op[type];
>   
> -	if (level == 0)
> -		level = ops->default_level;
> -	else
> -		level = min(max(level, ops->min_level), ops->max_level);
> -
> -	return level;
> +	return level == 0 ? ops->default_level : clamp(level, ops->min_level, ops->max_level);
>   }
>   
>   /*


  reply	other threads:[~2025-06-28  4:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-28  4:32 George Hu
2025-06-28  4:48 ` Qu Wenruo [this message]
2025-06-28  5:21   ` [PATCH v2] " George Hu
2025-06-28  5:26     ` Qu Wenruo
2025-06-30 16:12     ` 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=669773b7-4428-43ca-ab80-d7ed1c71886c@suse.com \
    --to=wqu@suse.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=integral@archlinux.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®