Messages in this thread Patch in this message | | | From | Wei Yang <> | Subject | [PATCH 2/9] XArray: simplify the calculation of shift | Date | Mon, 30 Mar 2020 12:36:36 +0000 |
| |
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
| |