lkml.org 
[lkml]   [2018]   [Sep]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] radix-tree: optimization for radix_tree_init_maxnodes
Date
if i == 0, height_to_maxnodes[i] = 0,
if i >= 1, height_to_maxnodes[i] = height_to_maxnodes[i-1]
+ __maxindex(i-1) + 1.

so delete height_to_maxindex and optimize the calculation of
height_to_maxnodes array.

Signed-off-by: Wang Long <wanglong19@meituan.com>
---
lib/radix-tree.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index bc03ecc..af02b2c 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -2242,14 +2242,11 @@ static __init unsigned long __maxindex(unsigned int height)

static __init void radix_tree_init_maxnodes(void)
{
- unsigned long height_to_maxindex[RADIX_TREE_MAX_PATH + 1];
- unsigned int i, j;
-
- for (i = 0; i < ARRAY_SIZE(height_to_maxindex); i++)
- height_to_maxindex[i] = __maxindex(i);
- for (i = 0; i < ARRAY_SIZE(height_to_maxnodes); i++) {
- for (j = i; j > 0; j--)
- height_to_maxnodes[i] += height_to_maxindex[j - 1] + 1;
+ unsigned int i;
+
+ for (i = 1; i < ARRAY_SIZE(height_to_maxnodes); i++) {
+ height_to_maxnodes[i] = height_to_maxnodes[i - 1]
+ + __maxindex(i - 1) + 1;
}
}

--
1.8.3.1
\
 
 \ /
  Last update: 2018-09-09 15:30    [W:0.122 / U:0.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site