]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Reduce _mas_store() code a bit
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 10 Dec 2020 18:47:32 +0000 (13:47 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Jan 2021 17:33:38 +0000 (12:33 -0500)
Also, wth about that else in ma_root_ptr??

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 12524a4e5589d820cd8ccf99c463fef1f909b462..f298048159737df25044dc54ce58733e94d9ff6c 100644 (file)
@@ -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 &&