rbtree: optimize case selection logic in __rb_erase_color()
authorMichel Lespinasse <[email protected]>
Mon, 8 Oct 2012 23:30:54 +0000 (16:30 -0700)
committerLinus Torvalds <[email protected]>
Tue, 9 Oct 2012 07:22:34 +0000 (16:22 +0900)
commite125d1471a4f8f1bf7ea9a83deb8d23cb40bd712
tree00c6bb561cdb8d0cb455563aa233bffe73b7e6db
parentd6ff1273928ebf15466a85b7e1810cd00e72998b
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 <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Acked-by: David Woodhouse <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Daniel Santos <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
lib/rbtree.c