*/
static inline unsigned char mas_data_end(const struct ma_state *mas)
{
- unsigned char offset = 0;
enum maple_type type = mte_node_type(mas->node);
+ unsigned char offset = mt_min_slots[type];
unsigned long piv, *pivots = ma_pivots(mas_mn(mas), type);
- while (offset < mt_slots[type]) {
- piv = _mas_safe_pivot(mas, pivots, offset, type);
- if ((!piv && offset) || piv >= mas->max)
- break;
- offset++;
+ if (pivots[offset]) {
+ while (offset < mt_slots[type]) {
+ piv = _mas_safe_pivot(mas, pivots, offset, type);
+ if ((!piv && offset) || piv >= mas->max)
+ break;
+ offset++;
+ }
+ } else {
+ offset--;
+ do {
+ if (pivots[offset])
+ break;
+ } while (--offset);
}
return offset;