rbtree: optimize case selection logic in __rb_erase_color()
authorMichel Lespinasse <walken@google.com>
Wed, 20 Dec 2017 17:03:31 +0000 (18:03 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 20 Dec 2017 17:03:31 +0000 (18:03 +0100)
commitea9733f4aec3b6f4d800fd9e4287e4fc3812c4a3
treecc5134191519b5f8f991a6c3153bbb6cbdb48333
parent96bc157a7c71c8e3687e2aeb5b4c3cdef5f4141c
rbtree: optimize case selection logic in __rb_erase_color()

In __rb_erase_color(), we have to select one of 3 cases depending on the
color on the 'other' node children.  If both children are black, we flip a
few node colors and iterate.  Otherwise, we do either one or two tree
rotations, depending on the color of the 'other' child opposite to 'node',
and then we are done.

The corresponding logic had duplicate checks for the color of the 'other'
child opposite to 'node'.  It was checking it first to determine if both
children are black, and then to determine how many tree rotations are
required.  Rearrange the logic to avoid that extra check.

Signed-off-by: Michel Lespinasse <walken@google.com>
Acked-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[Linux commit e125d1471a4f8f1bf7ea9a83deb8d23cb40bd712]

Ported to Xen.

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