Define RB_SET_PARENT to do all assignments to rb parent
pointers. Define RB_SWAP_CHILD to replace the child of a parent with its twin, and use it in 4 places. Use RB_SET in rb_link_node to remove the only linuxkpi reference to color, and then drop color- and parent-related definitions that are defined and used only in rbtree.h. This is intended to be entirely cosmetic, with no impact on program behavior, and leave RB_PARENT and RB_SET_PARENT as the only ways to read and write rb parent pointers. Reviewed by: markj, kib Tested by: pho Differential Revision: https://reviews.freebsd.org/D25264
This commit is contained in:
parent
bfd735d96e
commit
4d56980017
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=362552
@ -56,17 +56,11 @@ int panic_cmp(struct rb_node *one, struct rb_node *two);
|
|||||||
RB_HEAD(linux_root, rb_node);
|
RB_HEAD(linux_root, rb_node);
|
||||||
RB_PROTOTYPE(linux_root, rb_node, __entry, panic_cmp);
|
RB_PROTOTYPE(linux_root, rb_node, __entry, panic_cmp);
|
||||||
|
|
||||||
#define rb_parent(r) RB_PARENT(r, __entry)
|
|
||||||
#define rb_color(r) RB_COLOR(r, __entry)
|
|
||||||
#define rb_is_red(r) (rb_color(r) == RB_RED)
|
|
||||||
#define rb_is_black(r) (rb_color(r) == RB_BLACK)
|
|
||||||
#define rb_set_parent(r, p) rb_parent((r)) = (p)
|
|
||||||
#define rb_set_color(r, c) rb_color((r)) = (c)
|
|
||||||
#define rb_entry(ptr, type, member) container_of(ptr, type, member)
|
#define rb_entry(ptr, type, member) container_of(ptr, type, member)
|
||||||
|
|
||||||
#define RB_EMPTY_ROOT(root) RB_EMPTY((struct linux_root *)root)
|
#define RB_EMPTY_ROOT(root) RB_EMPTY((struct linux_root *)root)
|
||||||
#define RB_EMPTY_NODE(node) (rb_parent(node) == node)
|
#define RB_EMPTY_NODE(node) (RB_PARENT(node, __entry) == node)
|
||||||
#define RB_CLEAR_NODE(node) (rb_set_parent(node, node))
|
#define RB_CLEAR_NODE(node) (RB_SET_PARENT(node, node, __entry))
|
||||||
|
|
||||||
#define rb_insert_color(node, root) \
|
#define rb_insert_color(node, root) \
|
||||||
linux_root_RB_INSERT_COLOR((struct linux_root *)(root), (node))
|
linux_root_RB_INSERT_COLOR((struct linux_root *)(root), (node))
|
||||||
@ -81,9 +75,7 @@ static inline void
|
|||||||
rb_link_node(struct rb_node *node, struct rb_node *parent,
|
rb_link_node(struct rb_node *node, struct rb_node *parent,
|
||||||
struct rb_node **rb_link)
|
struct rb_node **rb_link)
|
||||||
{
|
{
|
||||||
rb_set_parent(node, parent);
|
RB_SET(node, parent, __entry);
|
||||||
rb_set_color(node, RB_RED);
|
|
||||||
node->__entry.rbe_left = node->__entry.rbe_right = NULL;
|
|
||||||
*rb_link = node;
|
*rb_link = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,20 +83,12 @@ static inline void
|
|||||||
rb_replace_node(struct rb_node *victim, struct rb_node *new,
|
rb_replace_node(struct rb_node *victim, struct rb_node *new,
|
||||||
struct rb_root *root)
|
struct rb_root *root)
|
||||||
{
|
{
|
||||||
struct rb_node *p;
|
|
||||||
|
|
||||||
p = rb_parent(victim);
|
RB_SWAP_CHILD((struct linux_root *)root, victim, new, __entry);
|
||||||
if (p) {
|
|
||||||
if (p->rb_left == victim)
|
|
||||||
p->rb_left = new;
|
|
||||||
else
|
|
||||||
p->rb_right = new;
|
|
||||||
} else
|
|
||||||
root->rb_node = new;
|
|
||||||
if (victim->rb_left)
|
if (victim->rb_left)
|
||||||
rb_set_parent(victim->rb_left, new);
|
RB_SET_PARENT(victim->rb_left, new, __entry);
|
||||||
if (victim->rb_right)
|
if (victim->rb_right)
|
||||||
rb_set_parent(victim->rb_right, new);
|
RB_SET_PARENT(victim->rb_right, new, __entry);
|
||||||
*new = *victim;
|
*new = *victim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,8 +325,12 @@ struct { \
|
|||||||
#define RB_ROOT(head) (head)->rbh_root
|
#define RB_ROOT(head) (head)->rbh_root
|
||||||
#define RB_EMPTY(head) (RB_ROOT(head) == NULL)
|
#define RB_EMPTY(head) (RB_ROOT(head) == NULL)
|
||||||
|
|
||||||
|
#define RB_SET_PARENT(dst, src, field) do { \
|
||||||
|
RB_PARENT(dst, field) = src; \
|
||||||
|
} while (/*CONSTCOND*/ 0)
|
||||||
|
|
||||||
#define RB_SET(elm, parent, field) do { \
|
#define RB_SET(elm, parent, field) do { \
|
||||||
RB_PARENT(elm, field) = parent; \
|
RB_SET_PARENT(elm, parent, field); \
|
||||||
RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \
|
RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \
|
||||||
RB_COLOR(elm, field) = RB_RED; \
|
RB_COLOR(elm, field) = RB_RED; \
|
||||||
} while (/*CONSTCOND*/ 0)
|
} while (/*CONSTCOND*/ 0)
|
||||||
@ -344,37 +348,36 @@ struct { \
|
|||||||
#define RB_AUGMENT(x) break
|
#define RB_AUGMENT(x) break
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define RB_SWAP_CHILD(head, out, in, field) do { \
|
||||||
|
if (RB_PARENT(out, field) == NULL) \
|
||||||
|
RB_ROOT(head) = (in); \
|
||||||
|
else if ((out) == RB_LEFT(RB_PARENT(out, field), field)) \
|
||||||
|
RB_LEFT(RB_PARENT(out, field), field) = (in); \
|
||||||
|
else \
|
||||||
|
RB_RIGHT(RB_PARENT(out, field), field) = (in); \
|
||||||
|
} while (/*CONSTCOND*/ 0)
|
||||||
|
|
||||||
#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \
|
#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \
|
||||||
(tmp) = RB_RIGHT(elm, field); \
|
(tmp) = RB_RIGHT(elm, field); \
|
||||||
if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \
|
if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \
|
||||||
RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \
|
RB_SET_PARENT(RB_RIGHT(elm, field), elm, field); \
|
||||||
} \
|
} \
|
||||||
if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \
|
RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \
|
||||||
if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
|
RB_SWAP_CHILD(head, elm, tmp, field); \
|
||||||
RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
|
|
||||||
else \
|
|
||||||
RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
|
|
||||||
} else \
|
|
||||||
(head)->rbh_root = (tmp); \
|
|
||||||
RB_LEFT(tmp, field) = (elm); \
|
RB_LEFT(tmp, field) = (elm); \
|
||||||
RB_PARENT(elm, field) = (tmp); \
|
RB_SET_PARENT(elm, tmp, field); \
|
||||||
RB_AUGMENT(elm); \
|
RB_AUGMENT(elm); \
|
||||||
} while (/*CONSTCOND*/ 0)
|
} while (/*CONSTCOND*/ 0)
|
||||||
|
|
||||||
#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \
|
#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \
|
||||||
(tmp) = RB_LEFT(elm, field); \
|
(tmp) = RB_LEFT(elm, field); \
|
||||||
if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \
|
if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \
|
||||||
RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \
|
RB_SET_PARENT(RB_LEFT(elm, field), elm, field); \
|
||||||
} \
|
} \
|
||||||
if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \
|
RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \
|
||||||
if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
|
RB_SWAP_CHILD(head, elm, tmp, field); \
|
||||||
RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
|
|
||||||
else \
|
|
||||||
RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
|
|
||||||
} else \
|
|
||||||
(head)->rbh_root = (tmp); \
|
|
||||||
RB_RIGHT(tmp, field) = (elm); \
|
RB_RIGHT(tmp, field) = (elm); \
|
||||||
RB_PARENT(elm, field) = (tmp); \
|
RB_SET_PARENT(elm, tmp, field); \
|
||||||
RB_AUGMENT(elm); \
|
RB_AUGMENT(elm); \
|
||||||
} while (/*CONSTCOND*/ 0)
|
} while (/*CONSTCOND*/ 0)
|
||||||
|
|
||||||
@ -545,11 +548,11 @@ name##_RB_REMOVE_COLOR(struct name *head, struct type *parent) \
|
|||||||
attr struct type * \
|
attr struct type * \
|
||||||
name##_RB_REMOVE(struct name *head, struct type *elm) \
|
name##_RB_REMOVE(struct name *head, struct type *elm) \
|
||||||
{ \
|
{ \
|
||||||
struct type *child, *old, *parent, *parent_old, *right; \
|
struct type *child, *old, *parent, *right; \
|
||||||
int color; \
|
int color; \
|
||||||
\
|
\
|
||||||
old = elm; \
|
old = elm; \
|
||||||
parent_old = parent = RB_PARENT(elm, field); \
|
parent = RB_PARENT(elm, field); \
|
||||||
right = RB_RIGHT(elm, field); \
|
right = RB_RIGHT(elm, field); \
|
||||||
color = RB_COLOR(elm, field); \
|
color = RB_COLOR(elm, field); \
|
||||||
if (RB_LEFT(elm, field) == NULL) \
|
if (RB_LEFT(elm, field) == NULL) \
|
||||||
@ -568,20 +571,15 @@ name##_RB_REMOVE(struct name *head, struct type *elm) \
|
|||||||
child = RB_RIGHT(elm, field); \
|
child = RB_RIGHT(elm, field); \
|
||||||
parent = RB_PARENT(elm, field); \
|
parent = RB_PARENT(elm, field); \
|
||||||
RB_LEFT(parent, field) = child; \
|
RB_LEFT(parent, field) = child; \
|
||||||
RB_PARENT(RB_RIGHT(old, field), field) = elm; \
|
RB_SET_PARENT(RB_RIGHT(old, field), elm, field); \
|
||||||
} \
|
} \
|
||||||
RB_PARENT(RB_LEFT(old, field), field) = elm; \
|
RB_SET_PARENT(RB_LEFT(old, field), elm, field); \
|
||||||
color = RB_COLOR(elm, field); \
|
color = RB_COLOR(elm, field); \
|
||||||
elm->field = old->field; \
|
elm->field = old->field; \
|
||||||
} \
|
} \
|
||||||
if (parent_old == NULL) \
|
RB_SWAP_CHILD(head, old, elm, field); \
|
||||||
RB_ROOT(head) = elm; \
|
|
||||||
else if (RB_LEFT(parent_old, field) == old) \
|
|
||||||
RB_LEFT(parent_old, field) = elm; \
|
|
||||||
else \
|
|
||||||
RB_RIGHT(parent_old, field) = elm; \
|
|
||||||
if (child != NULL) { \
|
if (child != NULL) { \
|
||||||
RB_PARENT(child, field) = parent; \
|
RB_SET_PARENT(child, parent, field); \
|
||||||
RB_COLOR(child, field) = RB_BLACK; \
|
RB_COLOR(child, field) = RB_BLACK; \
|
||||||
} else if (color != RB_RED && parent != NULL) \
|
} else if (color != RB_RED && parent != NULL) \
|
||||||
name##_RB_REMOVE_COLOR(head, parent); \
|
name##_RB_REMOVE_COLOR(head, parent); \
|
||||||
|
Loading…
Reference in New Issue
Block a user