Skip to content

Commit 97f7e09

Browse files
Peng Zhangakpm00
Peng Zhang
authored andcommitted
maple_tree: simplify mas_wr_node_walk()
Simplify code of mas_wr_node_walk() without changing functionality, and improve readability. Remove some special judgments. Instead of dynamically recording the min and max in the loop, get the final min and max directly at the end. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Peng Zhang <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 9bc47f1 commit 97f7e09

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

lib/maple_tree.c

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,9 +2312,7 @@ static inline struct maple_enode *mte_node_or_none(struct maple_enode *enode)
23122312
static inline void mas_wr_node_walk(struct ma_wr_state *wr_mas)
23132313
{
23142314
struct ma_state *mas = wr_mas->mas;
2315-
unsigned char count;
2316-
unsigned char offset;
2317-
unsigned long index, min, max;
2315+
unsigned char count, offset;
23182316

23192317
if (unlikely(ma_is_dense(wr_mas->type))) {
23202318
wr_mas->r_max = wr_mas->r_min = mas->index;
@@ -2327,34 +2325,12 @@ static inline void mas_wr_node_walk(struct ma_wr_state *wr_mas)
23272325
count = wr_mas->node_end = ma_data_end(wr_mas->node, wr_mas->type,
23282326
wr_mas->pivots, mas->max);
23292327
offset = mas->offset;
2330-
min = mas_safe_min(mas, wr_mas->pivots, offset);
2331-
if (unlikely(offset == count))
2332-
goto max;
2333-
2334-
max = wr_mas->pivots[offset];
2335-
index = mas->index;
2336-
if (unlikely(index <= max))
2337-
goto done;
2338-
2339-
if (unlikely(!max && offset))
2340-
goto max;
23412328

2342-
min = max + 1;
2343-
while (++offset < count) {
2344-
max = wr_mas->pivots[offset];
2345-
if (index <= max)
2346-
goto done;
2347-
else if (unlikely(!max))
2348-
break;
2349-
2350-
min = max + 1;
2351-
}
2329+
while (offset < count && mas->index > wr_mas->pivots[offset])
2330+
offset++;
23522331

2353-
max:
2354-
max = mas->max;
2355-
done:
2356-
wr_mas->r_max = max;
2357-
wr_mas->r_min = min;
2332+
wr_mas->r_max = offset < count ? wr_mas->pivots[offset] : mas->max;
2333+
wr_mas->r_min = mas_safe_min(mas, wr_mas->pivots, offset);
23582334
wr_mas->offset_end = mas->offset = offset;
23592335
}
23602336

0 commit comments

Comments
 (0)