]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Optimize _mas_walk
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Sun, 17 Feb 2019 22:01:21 +0000 (17:01 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 31 Jul 2019 14:52:41 +0000 (10:52 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 3f0aeee47063f4985732d82151bbf4e731e2800a..b2f7cbddf7e183f9cc21d8d84689f1944fc66a73 100644 (file)
@@ -1284,16 +1284,18 @@ static inline bool _mas_walk(struct ma_state *mas)
        enum maple_type type;
        struct maple_node *next;
        unsigned long pivot_cnt, pivot, max, min, i;
+       bool ret = true;
 
        mas->node = mas_start(mas);
+       min = mas->min;
+       max = mas->max;
 
        while (true) {
                type = mt_node_type(mas->node);
                pivot_cnt = mt_pivots[type];
-               min = mas->min;
-               max = mas->max;
 
-               if (pivot_cnt) {
+               switch (type) {
+               default:
                        pivot = 0;
                        for (i = 0; i < pivot_cnt; i++) {
                                pivot = _ma_get_pivot(mas->node, i, type);
@@ -1309,30 +1311,34 @@ static inline bool _mas_walk(struct ma_state *mas)
                                min = pivot;
                        }
 
-                       if (i == pivot_cnt - 1) {
-                               if (mas->index > pivot)
+                       if ((i == pivot_cnt - 1) && (mas->index > pivot))
                                        i++;
-                       }
-               } else {
+
+                       if (type < maple_range_16) // Leaf.
+                               goto done;
+                       break;
+
+               case maple_dense:
                        // Linear node.
                        i = mas->index - mas->min;
                        if (mas->min)
                                i--;
+                       goto done;
+                       break;
                }
 
-               ma_set_slot(mas, i);
-               if (type < maple_range_16) // Leaf.
-                       return true;
-
                next = _ma_get_rcu_slot(mas->node, i, type);
                if (!next) // Not found.
-                       return type < maple_range_16;
+                       goto done;
 
                // Traverse.
                mas->max = max;
                mas->min = min;
                mas->node = next;
        }
+done:
+       ma_set_slot(mas, i);
+       return ret;
 }
 
 static inline void ma_insert(struct ma_state *mas, void *entry)