Prior to ending the ascension loop of larger operations like split, rebalance, and spanning store the gap in the node had been calculated. Once the node is inserted into the tree, the gap is recalculated in mas_update_gap(). This can be avoided by creating a helper for mas_update_gap() that accepts the known gap value, which reduces the operations required for gap updating path.
Showing the changes to lib (1 of 1 file). Show all
Unified · Split
| @@ -1566,14 +1566,26 @@ ascend: · 1565 unmodified lines | ||
| 1566 | 1566 | goto ascend; |
| 1567 | 1567 | } |
| 1568 | 1568 | |
| 1569 | +static __always_inline void mas_update_gap_known(struct ma_state *mas, | |
| 1570 | + unsigned long gap) | |
| 1571 | +{ | |
| 1572 | + unsigned char pslot; | |
| 1573 | + unsigned long p_gap; | |
| 1574 | + | |
| 1575 | + pslot = mte_parent_slot(mas->node); | |
| 1576 | + p_gap = ma_gaps(mte_parent(mas->node), | |
| 1577 | + mas_parent_type(mas, mas->node))[pslot]; | |
| 1578 | + | |
| 1579 | + if (p_gap != gap) | |
| 1580 | + mas_parent_gap(mas, pslot, gap); | |
| 1581 | +} | |
| 1582 | + | |
| 1569 | 1583 | /* |
| 1570 | 1584 | * mas_update_gap() - Update a nodes gaps and propagate up if necessary. |
| 1571 | 1585 | * @mas: the maple state. |
| 1572 | 1586 | */ |
| 1573 | 1587 | static inline void mas_update_gap(struct ma_state *mas) |
| 1574 | 1588 | { |
| 1575 | − unsigned char pslot; | |
| 1576 | − unsigned long p_gap; | |
| 1577 | 1589 | unsigned long max_gap; |
| 1578 | 1590 | |
| 1579 | 1591 | if (!mt_is_alloc(mas->tree)) |
| @@ -1583,13 +1595,7 @@ static inline void mas_update_gap(struct ma_state *mas) · 3 unmodified lines | ||
| 1583 | 1595 | return; |
| 1584 | 1596 | |
| 1585 | 1597 | max_gap = mas_max_gap(mas); |
| 1586 | − | |
| 1587 | − pslot = mte_parent_slot(mas->node); | |
| 1588 | − p_gap = ma_gaps(mte_parent(mas->node), | |
| 1589 | − mas_parent_type(mas, mas->node))[pslot]; | |
| 1590 | − | |
| 1591 | − if (p_gap != max_gap) | |
| 1592 | − mas_parent_gap(mas, pslot, max_gap); | |
| 1598 | + mas_update_gap_known(mas, max_gap); | |
| 1593 | 1599 | } |
| 1594 | 1600 | |
| 1595 | 1601 | /* |
| @@ -2137,8 +2143,8 @@ static inline void mas_wmb_replace(struct ma_state *mas, struct maple_copy *cp) · 541 unmodified lines | ||
| 2137 | 2143 | mas->node = mt_slot_locked(mas->tree, cp->slot, 0); |
| 2138 | 2144 | /* Insert the new data in the tree */ |
| 2139 | 2145 | mas_topiary_replace(mas, old_enode, cp->height); |
| 2140 | − if (!mte_is_leaf(mas->node)) | |
| 2141 | − mas_update_gap(mas); | |
| 2146 | + if (mt_is_alloc(mas->tree) && !mte_is_root(mas->node)) | |
| 2147 | + mas_update_gap_known(mas, cp->gap[0]); | |
| 2142 | 2148 | |
| 2143 | 2149 | mtree_range_walk(mas); |
| 2144 | 2150 | } |