From 48450c70380f40d824eece6c088a3994ad451c5f Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 27 Oct 2020 22:16:23 -0400 Subject: [PATCH] maple_tree: Reduce variables by using mas->offset directly Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 51 +++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index e26896b00479..947fa7dd92ae 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1689,8 +1689,6 @@ static inline bool mas_prev_sibling(struct ma_state *mas) */ static inline bool mas_next_sibling(struct ma_state *mas) { - unsigned char p_slot = mte_parent_slot(mas->node) + 1; - MA_STATE(parent, mas->tree, mas->index, mas->last); if (mte_is_root(mas->node)) @@ -1698,15 +1696,15 @@ static inline bool mas_next_sibling(struct ma_state *mas) mas_dup_state(&parent, mas); mas_ascend(&parent); + parent.offset = mte_parent_slot(mas->node) + 1; - if (p_slot == mt_slot_count(parent.node)) + if (parent.offset == mt_slot_count(parent.node)) return false; - if (!mas_get_slot(&parent, p_slot)) + if (!mas_get_slot(&parent, parent.offset)) return false; mas_dup_state(mas, &parent); - mas->offset = p_slot; mas_descend(mas); return true; } @@ -2878,21 +2876,20 @@ static inline bool mas_node_walk(struct ma_state *mas, enum maple_type type, { unsigned long *pivots = ma_pivots(mas_mn(mas), type); unsigned long min, pivot = 0; - unsigned char i = mas->offset; - min = mas_safe_min(mas, pivots, i); + min = mas_safe_min(mas, pivots, mas->offset); if (ma_is_dense(type)) { // Linear node. // What if mas->index != mas->last? pivot = min = mas->index; - i = mas->index = mas->min; + mas->offset = mas->index = mas->min; goto dense; } - while(i < mt_slots[type]) { - pivot = _mas_safe_pivot(mas, pivots, i, type); + while(mas->offset < mt_slots[type]) { + pivot = _mas_safe_pivot(mas, pivots, mas->offset, type); - if (!pivot && i) { + if (!pivot && mas->offset) { if (mas->max < mas->index) { mas->offset = MAPLE_NODE_SLOTS; return false; @@ -2905,13 +2902,12 @@ static inline bool mas_node_walk(struct ma_state *mas, enum maple_type type, break; min = pivot + 1; - i++; + mas->offset++; } dense: *range_min = min; *range_max = pivot; - mas->offset = i; return true; } @@ -3114,17 +3110,18 @@ static inline int mas_spanning_store(struct ma_state *mas, void *entry) static inline bool mas_node_store(struct ma_state *mas, void *entry, unsigned long min, unsigned long max, - unsigned char end, void *content, - unsigned char offset) + unsigned char end, void *content) { enum maple_type mt = mte_node_type(mas->node); struct maple_node *node = mas_mn(mas); void **dst_slots, **slots = ma_slots(node, mt); unsigned long *dst_pivots, *pivots = ma_pivots(node, mt); - unsigned char dst_offset, offset_end = offset, new_end = end; + unsigned char dst_offset, new_end = end; + unsigned char offset, offset_end; struct maple_node reuse, *newnode; unsigned char copy_size; + offset = offset_end = mas->offset; if (mas->last == max) { // don't copy this offset offset_end++; } else if (mas->last < max) { // new range ends in this range. @@ -3218,14 +3215,13 @@ done: static inline bool mas_slot_store(struct ma_state *mas, void *entry, unsigned long min, unsigned long max, - unsigned char end, void *content, - unsigned char offset) + unsigned char end, void *content) { enum maple_type mt = mte_node_type(mas->node); struct maple_node *node = mas_mn(mas); void **slots = ma_slots(node, mt); unsigned long *pivots = ma_pivots(node, mt); - unsigned long lmax; // Logical max. + unsigned long offset = mas->offset, lmax; // Logical max. if (min == mas->index && max == mas->last) { // exact fit. slots[offset] = entry; @@ -3256,7 +3252,6 @@ static inline bool mas_slot_store(struct ma_state *mas, void *entry, if (offset + 1 < mt_pivots[mt]) pivots[offset + 1] = mas->last; slots[offset + 1] = entry; - mas->offset = offset + 1; pivots[offset] = mas->index - 1; goto done; } @@ -3269,13 +3264,13 @@ done: return true; try_node_store: - return mas_node_store(mas, entry, min, max, end, content, offset); + return mas_node_store(mas, entry, min, max, end, content); } static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite) { unsigned long r_max, r_min; - unsigned char end, offset; + unsigned char end; void *content = NULL; struct maple_big_node b_node; @@ -3303,8 +3298,7 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite /* At this point, we are at the leaf node that needs to be altered. */ /* Calculate needed space */ - offset = mas->offset; - content = mas_get_slot(mas, offset); + content = mas_get_slot(mas, mas->offset); if (!overwrite && ((mas->last > r_max) || content)) { mas_set_err(mas, -EEXIST); return content; @@ -3317,19 +3311,18 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite MA_STATE(r_mas, mas->tree, mas->last, mas->last); - r_mas.offset = offset; + r_mas.offset = mas->offset; r_mas.node = mas->node; mas_node_walk(&r_mas, mte_node_type(r_mas.node), &rmin, &rmax); mas_extend_null(mas, &r_mas); mas->last = r_mas.last; - offset = mas->offset; - r_min = mas_safe_min(mas, pivots, offset); - r_max = _mas_safe_pivot(mas, pivots, offset, mt); + r_min = mas_safe_min(mas, pivots, mas->offset); + r_max = _mas_safe_pivot(mas, pivots, mas->offset, mt); } end = mas_data_end(mas); - if (mas_slot_store(mas, entry, r_min, r_max, end, content, offset)) + if (mas_slot_store(mas, entry, r_min, r_max, end, content)) return content; if (mas_is_err(mas)) -- 2.50.1