public inbox for newlib-cvs@sourceware.org help / color / mirror / Atom feed
From: Sebastian Huber <sh@sourceware.org> To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Define RB_SET_PARENT to do all assignments Date: Mon, 26 Oct 2020 13:32:43 +0000 (GMT) [thread overview] Message-ID: <20201026133243.274FC3894C2C@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=17b7dfc0b55a0668178cdc18aa14e0221468b2bc commit 17b7dfc0b55a0668178cdc18aa14e0221468b2bc Author: dougm <dougm@FreeBSD.org> Date: Tue Jun 23 20:02:55 2020 +0000 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 Diff: --- newlib/libc/include/sys/tree.h | 58 ++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/newlib/libc/include/sys/tree.h b/newlib/libc/include/sys/tree.h index 2e1cc1eda..2af77a499 100644 --- a/newlib/libc/include/sys/tree.h +++ b/newlib/libc/include/sys/tree.h @@ -325,8 +325,12 @@ struct { \ #define RB_ROOT(head) (head)->rbh_root #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 { \ - RB_PARENT(elm, field) = parent; \ + RB_SET_PARENT(elm, parent, field); \ RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ RB_COLOR(elm, field) = RB_RED; \ } while (/*CONSTCOND*/ 0) @@ -344,37 +348,36 @@ struct { \ #define RB_AUGMENT(x) break #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 { \ (tmp) = RB_RIGHT(elm, field); \ 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) { \ - if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ - RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ - else \ - RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ - } else \ - (head)->rbh_root = (tmp); \ + RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \ + RB_SWAP_CHILD(head, elm, tmp, field); \ RB_LEFT(tmp, field) = (elm); \ - RB_PARENT(elm, field) = (tmp); \ + RB_SET_PARENT(elm, tmp, field); \ RB_AUGMENT(elm); \ } while (/*CONSTCOND*/ 0) #define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ (tmp) = RB_LEFT(elm, field); \ 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) { \ - if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ - RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ - else \ - RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ - } else \ - (head)->rbh_root = (tmp); \ + RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \ + RB_SWAP_CHILD(head, elm, tmp, field); \ RB_RIGHT(tmp, field) = (elm); \ - RB_PARENT(elm, field) = (tmp); \ + RB_SET_PARENT(elm, tmp, field); \ RB_AUGMENT(elm); \ } while (/*CONSTCOND*/ 0) @@ -545,11 +548,11 @@ name##_RB_REMOVE_COLOR(struct name *head, struct type *parent) \ attr struct type * \ 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; \ \ old = elm; \ - parent_old = parent = RB_PARENT(elm, field); \ + parent = RB_PARENT(elm, field); \ right = RB_RIGHT(elm, field); \ color = RB_COLOR(elm, field); \ if (RB_LEFT(elm, field) == NULL) \ @@ -568,20 +571,15 @@ name##_RB_REMOVE(struct name *head, struct type *elm) \ child = RB_RIGHT(elm, field); \ parent = RB_PARENT(elm, field); \ 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); \ elm->field = old->field; \ } \ - if (parent_old == NULL) \ - 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; \ + RB_SWAP_CHILD(head, old, elm, field); \ if (child != NULL) { \ - RB_PARENT(child, field) = parent; \ + RB_SET_PARENT(child, parent, field); \ RB_COLOR(child, field) = RB_BLACK; \ } else if (color != RB_RED && parent != NULL) \ name##_RB_REMOVE_COLOR(head, parent); \
reply other threads:[~2020-10-26 13:32 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20201026133243.274FC3894C2C@sourceware.org \ --to=sh@sourceware.org \ --cc=newlib-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).