From: Liam R. Howlett Date: Fri, 6 Nov 2020 21:50:55 +0000 (-0500) Subject: maple_tree: Optimizations and whitespace. nothing interesting X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=92226656d45f64a675cc75f9bb84c38e590bfbc5;p=users%2Fjedix%2Flinux-maple.git maple_tree: Optimizations and whitespace. nothing interesting Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 39c3b6fe11b1..a6e8736b312c 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -28,7 +28,7 @@ #define ma_enode_ptr(x) ((struct maple_enode *)(x)) static struct kmem_cache *maple_node_cache; -unsigned long mt_max[] = { +static const unsigned long mt_max[] = { [maple_dense] = MAPLE_NODE_SLOTS, [maple_leaf_64] = ULONG_MAX, [maple_range_64] = ULONG_MAX, @@ -36,7 +36,7 @@ unsigned long mt_max[] = { }; #define mt_node_max(x) mt_max[mte_node_type(x)] -unsigned char mt_slots[] = { +static const unsigned char mt_slots[] = { [maple_dense] = MAPLE_NODE_SLOTS, [maple_leaf_64] = MAPLE_RANGE64_SLOTS, [maple_range_64] = MAPLE_RANGE64_SLOTS, @@ -44,7 +44,7 @@ unsigned char mt_slots[] = { }; #define mt_slot_count(x) mt_slots[mte_node_type(x)] -unsigned char mt_pivots[] = { +static const unsigned char mt_pivots[] = { [maple_dense] = 0, [maple_leaf_64] = MAPLE_RANGE64_SLOTS - 1, [maple_range_64] = MAPLE_RANGE64_SLOTS - 1, @@ -52,7 +52,7 @@ unsigned char mt_pivots[] = { }; #define mt_pivot_count(x) mt_pivots[mte_node_type(x)] -unsigned char mt_min_slots[] = { +static const unsigned char mt_min_slots[] = { [maple_dense] = MAPLE_NODE_SLOTS / 2, [maple_leaf_64] = (MAPLE_RANGE64_SLOTS / 2) - 2, [maple_range_64] = (MAPLE_RANGE64_SLOTS / 2) - 2, @@ -1084,7 +1084,7 @@ static inline unsigned long mas_leaf_max_gap(struct ma_state *mas) unsigned char max_piv; if (ma_is_dense(mt)) { - for (i = 0; i < mt_slot_count(mas->node); i++) { + for (i = 0; i < mt_slots[mt]; i++) { if (slots[i]) { if (gap > max_gap) max_gap = gap; @@ -1113,7 +1113,6 @@ static inline unsigned long mas_leaf_max_gap(struct ma_state *mas) if (slots[i]) goto next; - gap = pend - pstart + 1; if (gap > max_gap) max_gap = gap; @@ -2965,10 +2964,6 @@ static inline bool mas_node_walk(struct ma_state *mas, enum maple_type type, pivot = _mas_safe_pivot(mas, pivots, mas->offset, type); if (!pivot && mas->offset) { - if (mas->max < mas->index) { - mas->offset = MAPLE_NODE_SLOTS; - return false; - } pivot = mas->max; break; } @@ -3295,7 +3290,8 @@ static inline bool mas_slot_store(struct ma_state *mas, void *entry, struct maple_node *node = mas_mn(mas); void **slots = ma_slots(node, mt); unsigned long *pivots = ma_pivots(node, mt); - unsigned long offset = mas->offset, lmax; // Logical max. + unsigned long lmax; // Logical max. + unsigned char offset = mas->offset; if (min == mas->index && max == mas->last) { // exact fit. slots[offset] = entry; @@ -3316,6 +3312,7 @@ static inline bool mas_slot_store(struct ma_state *mas, void *entry, if (lmax <= mas->last) // overwriting two or more ranges with one. goto try_node_store; + // Overwriting a portion of offset + 1. slots[offset] = entry; pivots[offset] = mas->last; goto done; @@ -3327,6 +3324,7 @@ static inline bool mas_slot_store(struct ma_state *mas, void *entry, pivots[offset + 1] = mas->last; slots[offset + 1] = entry; pivots[offset] = mas->index - 1; + mas->offset++; // Keep mas accurate. goto done; }