* [PATCH] btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level()
@ 2025-06-28 4:32 George Hu
2025-06-28 4:48 ` Qu Wenruo
0 siblings, 1 reply; 5+ messages in thread
From: George Hu @ 2025-06-28 4:32 UTC (permalink / raw)
To: Chris Mason, Josef Bacik, David Sterba
Cc: linux-btrfs, linux-kernel, 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.
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);
}
/*
--
2.50.0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level()
2025-06-28 4:32 [PATCH] btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level() George Hu
@ 2025-06-28 4:48 ` Qu Wenruo
2025-06-28 5:21 ` [PATCH v2] " George Hu
0 siblings, 1 reply; 5+ messages in thread
From: Qu Wenruo @ 2025-06-28 4:48 UTC (permalink / raw)
To: George Hu, Chris Mason, Josef Bacik, David Sterba
Cc: linux-btrfs, linux-kernel
在 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);
> }
>
> /*
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2] btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level()
2025-06-28 4:48 ` Qu Wenruo
@ 2025-06-28 5:21 ` George Hu
2025-06-28 5:26 ` Qu Wenruo
2025-06-30 16:12 ` David Sterba
0 siblings, 2 replies; 5+ messages in thread
From: George Hu @ 2025-06-28 5:21 UTC (permalink / raw)
To: wqu; +Cc: clm, dsterba, integral, josef, linux-btrfs, linux-kernel
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.
Signed-off-by: George Hu <integral@archlinux.org>
---
fs/btrfs/compression.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 48d07939fee4..be8d51c53f39 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -975,7 +975,7 @@ static int btrfs_compress_set_level(unsigned int type, int level)
if (level == 0)
level = ops->default_level;
else
- level = min(max(level, ops->min_level), ops->max_level);
+ level = clamp(level, ops->min_level, ops->max_level);
return level;
}
--
2.50.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level()
2025-06-28 5:21 ` [PATCH v2] " George Hu
@ 2025-06-28 5:26 ` Qu Wenruo
2025-06-30 16:12 ` David Sterba
1 sibling, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2025-06-28 5:26 UTC (permalink / raw)
To: George Hu, wqu; +Cc: clm, dsterba, josef, linux-btrfs, linux-kernel
在 2025/6/28 14:51, 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.
>
> Signed-off-by: George Hu <integral@archlinux.org>
Reviewed-by: Qu Wenruo <wqu@suse.com>
And merged into for-next branch.
Thanks,
Qu
> ---
> fs/btrfs/compression.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index 48d07939fee4..be8d51c53f39 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -975,7 +975,7 @@ static int btrfs_compress_set_level(unsigned int type, int level)
> if (level == 0)
> level = ops->default_level;
> else
> - level = min(max(level, ops->min_level), ops->max_level);
> + level = clamp(level, ops->min_level, ops->max_level);
>
> return level;
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level()
2025-06-28 5:21 ` [PATCH v2] " George Hu
2025-06-28 5:26 ` Qu Wenruo
@ 2025-06-30 16:12 ` David Sterba
1 sibling, 0 replies; 5+ messages in thread
From: David Sterba @ 2025-06-30 16:12 UTC (permalink / raw)
To: George Hu; +Cc: wqu, clm, dsterba, josef, linux-btrfs, linux-kernel
On Sat, Jun 28, 2025 at 01:21:30PM +0800, George Hu wrote:
> 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.
>
> Signed-off-by: George Hu <integral@archlinux.org>
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-06-30 16:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-28 4:32 [PATCH] btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level() George Hu
2025-06-28 4:48 ` Qu Wenruo
2025-06-28 5:21 ` [PATCH v2] " George Hu
2025-06-28 5:26 ` Qu Wenruo
2025-06-30 16:12 ` David Sterba
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®