btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level()
PATCH 1/1 btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level()
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.
--- fs/btrfs/compression.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
fs/btrfs/compression.c +1 -6
@@ -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); }/*
Signature · 1 line
2.50.0
Quoted 3 lines · George Hu
Refactor the
btrfs_compress_set_level()function by replacing the nested usage ofmin()andmax()macro withclamp()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
Quoted 24 lines
Signed-off-by George Hu <[email protected]>--- fs/btrfs/compression.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)fs/btrfs/compression.c +1
-6@@ -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); }/*
PATCH v2 1/1 btrfs: replace nested usage of min & max with clamp in btrfs_compress_set_level()
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.
--- fs/btrfs/compression.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/compression.c +1 -1
@@ -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; }
Signature · 1 line
2.50.0
Quoted 5 lines · George Hu
Refactor the
btrfs_compress_set_level()function by replacing the nested usage ofmin()andmax()macro withclamp()to simplify the code and improve readability.Signed-off-by George Hu <[email protected]>
And merged into for-next branch.
Thanks,
Qu
Quoted 17 lines
--- fs/btrfs/compression.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/compression.c +1
-1@@ -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; }
Quoted 5 lines · George Hu
Refactor the
btrfs_compress_set_level()function by replacing the nested usage ofmin()andmax()macro withclamp()to simplify the code and improve readability.Signed-off-by George Hu <[email protected]>