From 2986e90aad5453c3ec9cea45bf94ab8f0a12d52c Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 27 Oct 2020 22:40:18 -0400 Subject: [PATCH] maple_tree: Reduce variables by using mas->offset directly.. more. Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 77 ++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 947fa7dd92ae..ce4e13738b3a 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1205,7 +1205,6 @@ static inline unsigned long mas_first_entry(struct ma_state *mas, unsigned long limit) { void **slots, *entry; - int offset = 0; unsigned long range_start = mas->min; while (!mte_is_leaf(mas->node)) { @@ -1217,14 +1216,13 @@ static inline unsigned long mas_first_entry(struct ma_state *mas, slots = ma_slots(mte_to_node(mas->node), mte_node_type(mas->node)); - while ((range_start < limit) && (offset < mt_slot_count(mas->node))) { - entry = mas_slot(mas, slots, offset); - if (entry) { - mas->offset = offset; + mas->offset = 0; + while ((range_start < limit) && (mas->offset < mt_slot_count(mas->node))) { + entry = mas_slot(mas, slots, mas->offset); + if (entry) return range_start; - } - range_start = mas_safe_pivot(mas, offset) + 1; - offset++; + range_start = mas_safe_pivot(mas, mas->offset) + 1; + mas->offset++; } mas->node = MAS_NONE; @@ -3587,8 +3585,8 @@ static inline void *mas_last_entry(struct ma_state *mas, if (!mas_next_nentry(mas, limit, &range_start)) { entry = mas_get_slot(mas, slot - 1); if (mte_is_leaf(mas->node)) { - mas->index = range_start - 1; - mas->index = mte_pivot(mas->node, slot - 1); + mas->last = mte_pivot(mas->node, slot - 1); + mas->index = mte_pivot(mas->node, slot - 2) + 1; return entry; } @@ -3621,10 +3619,9 @@ static inline void *__mas_next(struct ma_state *mas, unsigned long limit, { void *entry = NULL; unsigned long index = mas->index; - unsigned char slot = mas->offset; - - mas->offset = slot + 1; + unsigned char slot; + mas->offset++; retry: *range_start = mas->last + 1; @@ -3889,22 +3886,23 @@ static inline bool _mas_walk(struct ma_state *mas, unsigned long *range_min, if (entry) return true; - if (mas_is_none(mas)) { - mas->offset = MAPLE_NODE_SLOTS; - return false; - } + if (mas_is_none(mas)) + goto not_found; if (mas_is_ptr(mas)) { *range_min = 0; *range_max = 0; if (!mas->index) return true; - mas->offset = MAPLE_NODE_SLOTS; - return false; + + goto not_found; } - mas->offset = 0; return __mas_walk(mas, range_min, range_max); + +not_found: + mas->offset = MAPLE_NODE_SLOTS; + return false; } @@ -3928,18 +3926,16 @@ void *mas_walk(struct ma_state *mas) { unsigned long range_min, range_max; unsigned long index = mas->index; - unsigned char offset; _mas_walk(mas, &range_min, &range_max); retry: if (mas_dead_node(mas, index)) goto retry; - offset = mas->offset; - if (offset == MAPLE_NODE_SLOTS) + if (mas->offset == MAPLE_NODE_SLOTS) return NULL; // Not found. - return mas_get_slot(mas, offset); + return mas_get_slot(mas, mas->offset); } static inline bool mas_search_cont(struct ma_state *mas, unsigned long index, @@ -4231,7 +4227,6 @@ int mas_get_empty_area_rev(struct ma_state *mas, unsigned long min, static inline int mas_alloc(struct ma_state *mas, void *entry, unsigned long size, unsigned long *index) { - unsigned char slot = MAPLE_NODE_SLOTS; unsigned long min; mas_start(mas); @@ -4249,20 +4244,19 @@ static inline int mas_alloc(struct ma_state *mas, void *entry, if (mas_is_err(mas)) return xa_err(mas->node); - slot = mas->offset; - if (slot == MAPLE_NODE_SLOTS) + if (mas->offset == MAPLE_NODE_SLOTS) goto no_gap; - // At this point, mas->node points to the right node and we have a - // slot that has a sufficient gap. + // At this point, mas->node points to the right node and we have an + // offset that has a sufficient gap. min = mas->min; - if (slot) - min = mte_pivot(mas->node, slot - 1) + 1; + if (mas->offset) + min = mte_pivot(mas->node, mas->offset - 1) + 1; if (mas->index < min) mas->index = min; - return mas_fill_gap(mas, entry, slot, size, index); + return mas_fill_gap(mas, entry, mas->offset, size, index); no_gap: return -EBUSY; @@ -4281,7 +4275,6 @@ static inline int mas_rev_alloc(struct ma_state *mas, unsigned long min, unsigned long max, void *entry, unsigned long size, unsigned long *index) { - unsigned char slot = MAPLE_NODE_SLOTS; int ret = 0; ret = _mas_get_empty_area(mas, min, max, size, false); @@ -4291,11 +4284,10 @@ static inline int mas_rev_alloc(struct ma_state *mas, unsigned long min, if (mas_is_err(mas)) return xa_err(mas->node); - slot = mas->offset; - if (slot == MAPLE_NODE_SLOTS) + if (mas->offset == MAPLE_NODE_SLOTS) goto no_gap; - return mas_fill_gap(mas, entry, slot, size, index); + return mas_fill_gap(mas, entry, mas->offset, size, index); no_gap: return -EBUSY; @@ -4318,16 +4310,13 @@ static inline void *mas_range_load(struct ma_state *mas, unsigned long *range_mi retry: if (_mas_walk(mas, range_min, range_max)) { - unsigned char offset = MAPLE_NODE_SLOTS; - if (mas_is_ptr(mas) && mas->last == 0) return mte_safe_root(mas->tree->ma_root); - offset = mas->offset; - if (offset >= MAPLE_NODE_SLOTS) + if (mas->offset >= MAPLE_NODE_SLOTS) return NULL; - entry = mas_get_slot(mas, offset); + entry = mas_get_slot(mas, mas->offset); if (mte_dead_node(mas->node)) goto retry; } @@ -4403,7 +4392,6 @@ void *_mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max, unsigned long range_start = 0, range_end = 0; void *entry = NULL; bool leaf; - unsigned char slot; MA_STATE(mas, mt, *index, *index); @@ -4412,9 +4400,8 @@ void *_mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max, rcu_read_lock(); leaf = _mas_walk(&mas, &range_start, &range_end); - slot = mas.offset; - if (leaf == true && slot != MAPLE_NODE_SLOTS) - entry = mas_get_slot(&mas, slot); + if (leaf == true && mas.offset != MAPLE_NODE_SLOTS) + entry = mas_get_slot(&mas, mas.offset); mas.last = range_end; if (!entry || xa_is_zero(entry)) -- 2.50.1