diff mbox series

[8/8] maple_tree: refine mab_calc_split function

Message ID 20221220142606.1698836-9-vernon2gm@gmail.com (mailing list archive)
State New
Headers show
Series Clean up and refinement for maple tree | expand

Commit Message

Vernon Yang Dec. 20, 2022, 2:26 p.m. UTC
Invert the conditional judgment of the mid_split, to focus
the return statement in the last statement, which is easier
to understand and for better readability.

Signed-off-by: Vernon Yang <vernon2gm@gmail.com>
---
 lib/maple_tree.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Liam R. Howlett Dec. 20, 2022, 3:05 p.m. UTC | #1
* Vernon Yang <vernon2gm@gmail.com> [221220 09:26]:
> Invert the conditional judgment of the mid_split, to focus
> the return statement in the last statement, which is easier
> to understand and for better readability.
> 
> Signed-off-by: Vernon Yang <vernon2gm@gmail.com>
> ---
>  lib/maple_tree.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 16cdcf309e97..d147669fb99c 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -1882,10 +1882,9 @@ static inline int mab_calc_split(struct ma_state *mas,
>  
>  	/* Avoid ending a node on a NULL entry */
>  	split = mab_no_null_split(bn, split, slot_count);
> -	if (!(*mid_split))
> -		return split;
>  
> -	*mid_split = mab_no_null_split(bn, *mid_split, slot_count);
> +	if (*mid_split)
> +		*mid_split = mab_no_null_split(bn, *mid_split, slot_count);

The function is written this way because mid_split is almost always
zero.  If you want to change this, then we should add an unlikely() to
the if statement.

>  
>  	return split;
>  }
> -- 
> 2.34.1
> 
>
Vernon Yang Dec. 21, 2022, 5:18 a.m. UTC | #2
On Tue, Dec 20, 2022 at 03:05:52PM +0000, Liam Howlett wrote:
> * Vernon Yang <vernon2gm@gmail.com> [221220 09:26]:
> > Invert the conditional judgment of the mid_split, to focus
> > the return statement in the last statement, which is easier
> > to understand and for better readability.
> >
> > Signed-off-by: Vernon Yang <vernon2gm@gmail.com>
> > ---
> >  lib/maple_tree.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> > index 16cdcf309e97..d147669fb99c 100644
> > --- a/lib/maple_tree.c
> > +++ b/lib/maple_tree.c
> > @@ -1882,10 +1882,9 @@ static inline int mab_calc_split(struct ma_state *mas,
> >
> >  	/* Avoid ending a node on a NULL entry */
> >  	split = mab_no_null_split(bn, split, slot_count);
> > -	if (!(*mid_split))
> > -		return split;
> >
> > -	*mid_split = mab_no_null_split(bn, *mid_split, slot_count);
> > +	if (*mid_split)
> > +		*mid_split = mab_no_null_split(bn, *mid_split, slot_count);
>
> The function is written this way because mid_split is almost always
> zero.  If you want to change this, then we should add an unlikely() to
> the if statement.
Okay,thank you very much for the suggestion, I will add
an unlikely() to the if statement.

>
> >
> >  	return split;
> >  }
> > --
> > 2.34.1
> >
> >
diff mbox series

Patch

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 16cdcf309e97..d147669fb99c 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -1882,10 +1882,9 @@  static inline int mab_calc_split(struct ma_state *mas,
 
 	/* Avoid ending a node on a NULL entry */
 	split = mab_no_null_split(bn, split, slot_count);
-	if (!(*mid_split))
-		return split;
 
-	*mid_split = mab_no_null_split(bn, *mid_split, slot_count);
+	if (*mid_split)
+		*mid_split = mab_no_null_split(bn, *mid_split, slot_count);
 
 	return split;
 }