static inline bool _mas_rev_awalk(struct ma_state *mas, unsigned long size)
{
- enum maple_type type;
+ enum maple_type type = mte_node_type(mas->node);
+ unsigned char slot = mas_get_slot(mas);
unsigned long max, min = mas->min;
- unsigned char i;
+ unsigned long gap = 0;
bool found = false;
- unsigned long this_gap = 0;
-
- type = mte_node_type(mas->node);
- i = mas_get_slot(mas);
-
- max = _mas_get_safe_pivot(mas, i, type);
+ max = _mas_get_safe_pivot(mas, slot, type);
switch (type) {
case maple_leaf_64:
default:
do {
- min = mas_get_safe_lower_bound(mas, i);
+ min = mas_get_safe_lower_bound(mas, slot);
/* last is below this range */
if (mas->last < min)
goto next_slot;
}
if (ma_is_leaf(type)) {
- if (mas_get_rcu_slot(mas, i))
+ if (mas_get_rcu_slot(mas, slot))
goto next_slot;
- this_gap = max - min + 1;
-
+ gap = max - min + 1;
} else {
- this_gap = mte_get_gap(mas->node, i);
+ gap = mte_get_gap(mas->node, slot);
}
- if (mas->last - min + 1 < size)
+ if (size > mas->last - min + 1)
goto next_slot;
- if (size > this_gap)
+ if (size > gap)
goto next_slot;
if (ma_is_leaf(type)) {
mas->min = min;
- mas->max = min + this_gap - 1;
+ mas->max = min + gap - 1;
found = true;
}
break;
next_slot:
- if (!i)
+ if (!slot)
goto ascend;
max = min - 1;
- } while (i--);
+ } while (slot--);
break;
case maple_dense:
- i = mas->index - mas->min;
+ slot = mas->index - mas->min;
found = true;
break;
}
if (!ma_is_leaf(type)) { //descend
struct maple_enode *next;
- next = mas_get_rcu_slot(mas, i);
+ next = mas_get_rcu_slot(mas, slot);
mas->min = min;
mas->max = max;
if (mt_is_empty(next))
goto ascend;
mas->node = next;
- i = _mas_data_end(mas, mte_node_type(next), &max);
+ slot = _mas_data_end(mas, mte_node_type(next), &max);
}
- mas_set_slot(mas, i);
+ mas_set_slot(mas, slot);
return found;
ascend:
if (mte_is_root(mas->node))
mas_set_err(mas, -EBUSY);
- mas_set_slot(mas, i);
+ mas_set_slot(mas, slot);
return found;
}