]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Add helper for lower bound
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Sat, 18 Jul 2020 00:46:38 +0000 (20:46 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:05:36 +0000 (15:05 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 0c56767f5591e7de66f3c4c5465e2af560c7127f..eb1ad58669fa34f5c5757d385eac8fd22d73d0fe 100644 (file)
@@ -494,6 +494,7 @@ static inline unsigned long _mas_get_safe_pivot(const struct ma_state *mas,
 
        return _mte_get_pivot(mas->node, slot, type);
 }
+
 /** Private
  * mas_get_safe_pivot() - Return the pivot or the mas->max.
  *
@@ -507,6 +508,15 @@ static inline unsigned long mas_get_safe_pivot(const struct ma_state *mas,
        return _mas_get_safe_pivot(mas, slot, type);
 }
 
+static inline unsigned long mas_get_safe_lower_bound(struct ma_state *mas,
+                                                    unsigned char slot)
+{
+       if (!slot)
+               return mas->min;
+
+       return mas_get_safe_pivot(mas, slot - 1) + 1;
+}
+
 static inline void ma_set_pivot(struct maple_node *mn, unsigned char slot,
                enum maple_type type, unsigned long val)
 {
@@ -2997,11 +3007,7 @@ restart_prev_node:
                        unsigned long last_pivot;
                        unsigned long pivot = mas_get_safe_pivot(mas, slot);
 
-                       if (slot)
-                               min = mas_get_safe_pivot(mas, slot - 1) + 1;
-                       else
-                               min = mas->min;
-
+                       min = mas_get_safe_lower_bound(mas, slot);
                        if (pivot < limit)
                                goto no_entry;
 
@@ -3163,8 +3169,7 @@ static inline bool mas_next_nentry(struct ma_state *mas, unsigned long max,
        unsigned char count = mt_slot_count(mas->node);
        void *entry;
 
-       if (slot)
-               r_start = mas_get_safe_pivot(mas, slot - 1) + 1;
+       r_start = mas_get_safe_lower_bound(mas, slot);
 
        while (slot < count) {
                pivot = mas_get_safe_pivot(mas, slot);
@@ -3327,11 +3332,7 @@ static inline void* _mas_prev(struct ma_state *mas, unsigned long limit)
 
        mas->last = max;
        slot = mas_get_slot(mas);
-       if (slot)
-               mas->index = mas_get_safe_pivot(mas, slot - 1) + 1;
-       else
-               mas->index = mas->min;
-
+       mas->index = mas_get_safe_lower_bound(mas, slot);
        return mas_get_rcu_slot(mas, mas_get_slot(mas));
 }
 
@@ -3364,14 +3365,6 @@ void *mas_prev(struct ma_state *mas, unsigned long min)
 }
 EXPORT_SYMBOL_GPL(mas_prev);
 
-static inline unsigned long _mas_rev_awalk_min(struct ma_state *mas,
-                                              unsigned char slot,
-                                              enum maple_type type)
-{
-       if (!slot)
-               return mas->min;
-       return _mte_get_pivot(mas->node, slot - 1, type) + 1;
-}
 static inline bool _mas_rev_awalk(struct ma_state *mas, unsigned long size)
 {
        enum maple_type type;
@@ -3392,7 +3385,7 @@ static inline bool _mas_rev_awalk(struct ma_state *mas, unsigned long size)
                do {
                        void *entry = NULL;
 
-                       min = _mas_rev_awalk_min(mas, i, type);
+                       min = mas_get_safe_lower_bound(mas, i);
 
                        /* last is below this range */
                        if (mas->last < min)
@@ -3435,8 +3428,7 @@ next_slot:
        default:
 
                do {
-                       min = _mas_rev_awalk_min(mas, i, type);
-
+                       min = mas_get_safe_lower_bound(mas, i);
                        /* last is too little for this range */
                        if (mas->last < min)
                                goto next;
@@ -3557,8 +3549,7 @@ next:
        default:
                pivot = 0;
                i = mas_get_slot(mas);
-               if (i)
-                       min = _mas_get_safe_pivot(mas, i - 1, type) + 1;
+               min = mas_get_safe_lower_bound(mas, i);
                for (; i <= pivot_cnt; i++) {
                        unsigned long this_gap;
                        pivot = _mas_get_safe_pivot(mas, i, type);
@@ -3832,9 +3823,7 @@ static int mas_fill_gap(struct ma_state *mas, void *entry, unsigned char slot,
         */
        mas_ascend(mas);
        mas->max = mas_get_safe_pivot(mas, pslot);
-       if (pslot)
-               mas->min = mas_get_safe_pivot(mas, pslot - 1) + 1;
-
+       mas->min = mas_get_safe_lower_bound(mas, pslot);
        mas->node = mn;
        mas_set_slot(mas, slot);
        _mas_store(mas, entry, false);