lkml.org 
[lkml]   [2020]   [Mar]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/9] XArray: simplify the calculation of shift
Date
When head is NULL, shift is calculated from max. Currently we use a loop
to detect how many XA_CHUNK_SHIFT is need to cover max.

To achieve this, we can get number of bits max expands and round it up
to XA_CHUNK_SHIFT.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
lib/xarray.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/lib/xarray.c b/lib/xarray.c
index 1d9fab7db8da..6454cf3f5b4c 100644
--- a/lib/xarray.c
+++ b/lib/xarray.c
@@ -560,11 +560,7 @@ static int xas_expand(struct xa_state *xas, void *head)
unsigned long max = xas_max(xas);

if (!head) {
- if (max == 0)
- return 0;
- while ((max >> shift) >= XA_CHUNK_SIZE)
- shift += XA_CHUNK_SHIFT;
- return shift + XA_CHUNK_SHIFT;
+ return roundup(fls_long(max), XA_CHUNK_SHIFT);
} else if (xa_is_node(head)) {
node = xa_to_node(head);
shift = node->shift + XA_CHUNK_SHIFT;
--
2.23.0
\
 
 \ /
  Last update: 2020-03-30 14:38    [W:1.055 / U:0.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site