lkml.org 
[lkml]   [2019]   [Mar]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v1] lib/generic-radix-tree: Make good use of while (level--)
On Thu, Mar 21, 2019 at 5:32 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> There is no need to split postincrement in while (level--) type of loops.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> lib/generic-radix-tree.c | 10 ++--------
> 1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/lib/generic-radix-tree.c b/lib/generic-radix-tree.c
> index a7bafc413730..5a1818a0de1f 100644
> --- a/lib/generic-radix-tree.c
> +++ b/lib/generic-radix-tree.c
> @@ -59,13 +59,9 @@ void *__genradix_ptr(struct __genradix *radix, size_t offset)
> if (ilog2(offset) >= genradix_depth_shift(level))
> return NULL;
>
> - while (1) {
> + while (level--) {
> if (!n)
> return NULL;
> - if (!level)
> - break;
> -
> - level--;

My bad, this will need an additional check. before the loop.

>
> n = n->children[offset >> genradix_depth_shift(level)];
> offset &= genradix_depth_size(level) - 1;
> @@ -157,9 +153,7 @@ void *__genradix_iter_peek(struct genradix_iter *iter,
> if (ilog2(iter->offset) >= genradix_depth_shift(level))
> return NULL;
>
> - while (level) {
> - level--;
> -
> + while (level--) {
> i = (iter->offset >> genradix_depth_shift(level)) &
> (GENRADIX_ARY - 1);
>
> --
> 2.20.1
>


--
With Best Regards,
Andy Shevchenko

\
 
 \ /
  Last update: 2019-03-21 16:37    [W:0.029 / U:3.176 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site