From: Liam R. Howlett Date: Thu, 10 Dec 2020 18:47:32 +0000 (-0500) Subject: maple_tree: Reduce _mas_store() code a bit X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=21f59efd028d82fbda7326ca390b16ab41654365;p=users%2Fjedix%2Flinux-maple.git maple_tree: Reduce _mas_store() code a bit Also, wth about that else in ma_root_ptr?? Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 12524a4e5589..f29804815973 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -994,9 +994,6 @@ static inline struct maple_enode *mas_start(struct ma_state *mas) { void *entry = NULL; - if (unlikely(mas_is_err(mas))) - return NULL; - if (likely(mas_is_start(mas))) { struct maple_enode *root; @@ -2954,7 +2951,7 @@ static inline int ma_root_ptr(struct ma_state *mas, void *entry, bool overwrite) if (mas_root(mas) && mas->last == 0) { if (!overwrite) goto exists; - } else + } if (mas->last != 0) ret = mas_root_expand(mas, entry); @@ -3467,14 +3464,11 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite int ret = 0; - if (mas_is_err(mas)) - return NULL; - - if (mas_start(mas) || mas_is_none(mas) || mas->node == MAS_ROOT) { ret = ma_root_ptr(mas, entry, overwrite); if (mas_is_err(mas)) return NULL; + if (ret) goto complete_at_root; } @@ -3495,7 +3489,7 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite node = mas_mn(mas); slots = ma_slots(node, mt); content = slots[mas->offset]; - if (!overwrite && (content || (mas->last > r_max))) { + if (unlikely(!overwrite) && (content || (mas->last > r_max))) { mas_set_err(mas, -EEXIST); return content; } @@ -3504,13 +3498,13 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite unsigned char offset_end = mas->offset; if (!content) { - if (mas->index > r_min) - mas->index = r_min; + mas->index = r_min; if (mas->last < r_max) mas->last = r_max; // if this one is null the next and prev are not. } else { unsigned long *pivots = ma_pivots(node, mt); + // Check next slot if we are overwriting the end. if ((mas->last == r_max) && !slots[mas->offset + 1]) { if (mas->offset < mt_pivots[mt] - 1 &&