rbtree: adjust node color in __rb_erase_color() only when necessary
authorMichel Lespinasse <walken@google.com>
Wed, 20 Dec 2017 17:03:09 +0000 (18:03 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 20 Dec 2017 17:03:09 +0000 (18:03 +0100)
commit96bc157a7c71c8e3687e2aeb5b4c3cdef5f4141c
treed1ad2e095c34c64c1c76d4cca59596721e1b28b7
parentf448b22416bcfd2b191c01db353d0e20b057949b
rbtree: adjust node color in __rb_erase_color() only when necessary

In __rb_erase_color(), we were always setting a node to black after
exiting the main loop.  And in one case, after fixing up the tree to
satisfy all rbtree invariants, we were setting the current node to root
just to guarantee a loop exit, at which point the root would be set to
black.  However this is not necessary, as the root of an rbtree is already
known to be black.  The only case where the color flip is required is when
we exit the loop due to the current node being red, and it's easiest to
just do the flip at that point instead of doing it after the loop.

[adrian.hunter@intel.com: perf tools: fix build for another rbtree.c change]
Signed-off-by: Michel Lespinasse <walken@google.com>
Acked-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[Linux commit d6ff1273928ebf15466a85b7e1810cd00e72998b]

Ported only rbtree.c to Xen.

Signed-off-by: Praveen Kumar <kpraveen.lkml@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/common/rbtree.c