Index: sys/sys/tree.h =================================================================== --- sys/sys/tree.h +++ sys/sys/tree.h @@ -380,7 +380,6 @@ } 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_SET_PARENT(RB_RIGHT(elm, field), elm, field); \ } \ @@ -392,7 +391,6 @@ } 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_SET_PARENT(RB_LEFT(elm, field), elm, field); \ } \ @@ -465,19 +463,18 @@ name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ { \ struct type *child, *parent; \ - while ((parent = RB_PARENT(elm, field)) != NULL) { \ + for (; (parent = RB_PARENT(elm, field)) != NULL; elm = parent) {\ if (RB_LEFT(parent, field) == elm) { \ if (RB_RED_LEFT(parent, field)) { \ RB_FLIP_LEFT(parent, field); \ - return; \ + break; \ } \ RB_FLIP_RIGHT(parent, field); \ - if (RB_RED_RIGHT(parent, field)) { \ - elm = parent; \ + if (RB_RED_RIGHT(parent, field)) \ continue; \ - } \ if (!RB_RED_RIGHT(elm, field)) { \ RB_FLIP_LEFT(elm, field); \ + child = RB_RIGHT(elm, field); \ RB_ROTATE_LEFT(head, elm, child, field);\ if (RB_RED_LEFT(child, field)) \ RB_FLIP_RIGHT(elm, field); \ @@ -489,15 +486,14 @@ } else { \ if (RB_RED_RIGHT(parent, field)) { \ RB_FLIP_RIGHT(parent, field); \ - return; \ + break; \ } \ RB_FLIP_LEFT(parent, field); \ - if (RB_RED_LEFT(parent, field)) { \ - elm = parent; \ + if (RB_RED_LEFT(parent, field)) \ continue; \ - } \ if (!RB_RED_LEFT(elm, field)) { \ RB_FLIP_RIGHT(elm, field); \ + child = RB_LEFT(elm, field); \ RB_ROTATE_RIGHT(head, elm, child, field);\ if (RB_RED_RIGHT(child, field)) \ RB_FLIP_LEFT(elm, field); \ @@ -517,79 +513,77 @@ name##_RB_REMOVE_COLOR(struct name *head, \ struct type *parent, struct type *elm) \ { \ - struct type *sib; \ + struct type *child; \ if (RB_LEFT(parent, field) == elm && \ RB_RIGHT(parent, field) == elm) { \ RB_BITS(parent, field) &= ~RB_RED_MASK; \ elm = parent; \ - parent = RB_PARENT(elm, field); \ - if (parent == NULL) \ + if ((parent = RB_PARENT(elm, field)) == NULL) \ return; \ } \ do { \ if (RB_LEFT(parent, field) == elm) { \ if (!RB_RED_LEFT(parent, field)) { \ RB_FLIP_LEFT(parent, field); \ - return; \ + break; \ } \ if (RB_RED_RIGHT(parent, field)) { \ RB_FLIP_RIGHT(parent, field); \ - elm = parent; \ continue; \ } \ - sib = RB_RIGHT(parent, field); \ - if ((~RB_BITS(sib, field) & RB_RED_MASK) == 0) {\ - RB_BITS(sib, field) &= ~RB_RED_MASK; \ - elm = parent; \ + elm = RB_RIGHT(parent, field); \ + if ((~RB_BITS(elm, field) & RB_RED_MASK) == 0) {\ + RB_BITS(elm, field) &= ~RB_RED_MASK; \ continue; \ } \ - RB_FLIP_RIGHT(sib, field); \ - if (RB_RED_LEFT(sib, field)) \ + RB_FLIP_RIGHT(elm, field); \ + if (RB_RED_LEFT(elm, field)) \ RB_FLIP_LEFT(parent, field); \ - else if (!RB_RED_RIGHT(sib, field)) { \ + else if (!RB_RED_RIGHT(elm, field)) { \ RB_FLIP_LEFT(parent, field); \ - RB_ROTATE_RIGHT(head, sib, elm, field); \ - if (RB_RED_RIGHT(elm, field)) \ - RB_FLIP_LEFT(sib, field); \ - if (RB_RED_LEFT(elm, field)) \ + child = RB_LEFT(elm, field); \ + RB_ROTATE_RIGHT(head, elm, child, field); \ + if (RB_RED_RIGHT(child, field)) \ + RB_FLIP_LEFT(elm, field); \ + if (RB_RED_LEFT(child, field)) \ RB_FLIP_RIGHT(parent, field); \ - RB_BITS(elm, field) |= RB_RED_MASK; \ - sib = elm; \ + RB_BITS(child, field) |= RB_RED_MASK; \ + elm = child; \ } \ - RB_ROTATE_LEFT(head, parent, sib, field); \ + RB_ROTATE_LEFT(head, parent, elm, field); \ } else { \ if (!RB_RED_RIGHT(parent, field)) { \ RB_FLIP_RIGHT(parent, field); \ - return; \ + break; \ } \ if (RB_RED_LEFT(parent, field)) { \ RB_FLIP_LEFT(parent, field); \ - elm = parent; \ continue; \ } \ - sib = RB_LEFT(parent, field); \ - if ((~RB_BITS(sib, field) & RB_RED_MASK) == 0) {\ - RB_BITS(sib, field) &= ~RB_RED_MASK; \ - elm = parent; \ + elm = RB_LEFT(parent, field); \ + if ((~RB_BITS(elm, field) & RB_RED_MASK) == 0) {\ + RB_BITS(elm, field) &= ~RB_RED_MASK; \ continue; \ } \ - RB_FLIP_LEFT(sib, field); \ - if (RB_RED_RIGHT(sib, field)) \ + RB_FLIP_LEFT(elm, field); \ + if (RB_RED_RIGHT(elm, field)) \ RB_FLIP_RIGHT(parent, field); \ - else if (!RB_RED_LEFT(sib, field)) { \ + else if (!RB_RED_LEFT(elm, field)) { \ RB_FLIP_RIGHT(parent, field); \ - RB_ROTATE_LEFT(head, sib, elm, field); \ - if (RB_RED_LEFT(elm, field)) \ - RB_FLIP_RIGHT(sib, field); \ - if (RB_RED_RIGHT(elm, field)) \ + child = RB_RIGHT(elm, field); \ + RB_ROTATE_LEFT(head, elm, child, field); \ + if (RB_RED_LEFT(child, field)) \ + RB_FLIP_RIGHT(elm, field); \ + if (RB_RED_RIGHT(child, field)) \ RB_FLIP_LEFT(parent, field); \ - RB_BITS(elm, field) |= RB_RED_MASK; \ - sib = elm; \ + RB_BITS(child, field) |= RB_RED_MASK; \ + elm = child; \ } \ - RB_ROTATE_RIGHT(head, parent, sib, field); \ + RB_ROTATE_RIGHT(head, parent, elm, field); \ } \ break; \ - } while ((parent = RB_PARENT(elm, field)) != NULL); \ + } while (elm = parent, \ + (parent = RB_PARENT(elm, field)) != NULL); \ } #define RB_GENERATE_REMOVE(name, type, field, attr) \