deduplicate insert and delete logic in qr module
This commit is contained in:
parent
c9d56cddf2
commit
1ad06aa53b
@ -18,20 +18,6 @@ struct { \
|
||||
|
||||
#define qr_prev(a_qr, a_field) ((a_qr)->a_field.qre_prev)
|
||||
|
||||
#define qr_before_insert(a_qrelm, a_qr, a_field) do { \
|
||||
(a_qr)->a_field.qre_prev = (a_qrelm)->a_field.qre_prev; \
|
||||
(a_qr)->a_field.qre_next = (a_qrelm); \
|
||||
(a_qr)->a_field.qre_prev->a_field.qre_next = (a_qr); \
|
||||
(a_qrelm)->a_field.qre_prev = (a_qr); \
|
||||
} while (0)
|
||||
|
||||
#define qr_after_insert(a_qrelm, a_qr, a_field) do { \
|
||||
(a_qr)->a_field.qre_next = (a_qrelm)->a_field.qre_next; \
|
||||
(a_qr)->a_field.qre_prev = (a_qrelm); \
|
||||
(a_qr)->a_field.qre_next->a_field.qre_prev = (a_qr); \
|
||||
(a_qrelm)->a_field.qre_next = (a_qr); \
|
||||
} while (0)
|
||||
|
||||
/* a_qr_a can directly be a qr_next() macro, but a_qr_b cannot. */
|
||||
#define qr_meld(a_qr_a, a_qr_b, a_field) do { \
|
||||
(a_qr_b)->a_field.qre_prev->a_field.qre_next = \
|
||||
@ -43,6 +29,12 @@ struct { \
|
||||
(a_qr_b)->a_field.qre_prev->a_field.qre_next = (a_qr_b); \
|
||||
} while (0)
|
||||
|
||||
#define qr_before_insert(a_qrelm, a_qr, a_field) \
|
||||
qr_meld((a_qrelm), (a_qr), a_field)
|
||||
|
||||
#define qr_after_insert(a_qrelm, a_qr, a_field) \
|
||||
qr_before_insert(qr_next(a_qrelm, a_field), (a_qr), a_field)
|
||||
|
||||
/*
|
||||
* qr_meld() and qr_split() are functionally equivalent, so there's no need to
|
||||
* have two copies of the code.
|
||||
@ -50,14 +42,8 @@ struct { \
|
||||
#define qr_split(a_qr_a, a_qr_b, a_field) \
|
||||
qr_meld((a_qr_a), (a_qr_b), a_field)
|
||||
|
||||
#define qr_remove(a_qr, a_field) do { \
|
||||
(a_qr)->a_field.qre_prev->a_field.qre_next \
|
||||
= (a_qr)->a_field.qre_next; \
|
||||
(a_qr)->a_field.qre_next->a_field.qre_prev \
|
||||
= (a_qr)->a_field.qre_prev; \
|
||||
(a_qr)->a_field.qre_next = (a_qr); \
|
||||
(a_qr)->a_field.qre_prev = (a_qr); \
|
||||
} while (0)
|
||||
#define qr_remove(a_qr, a_field) \
|
||||
qr_split(qr_next(a_qr, a_field), (a_qr), a_field)
|
||||
|
||||
#define qr_foreach(var, a_qr, a_field) \
|
||||
for ((var) = (a_qr); \
|
||||
|
Loading…
Reference in New Issue
Block a user