rbtree: break out of rb_insert_color loop after tree rotation
authorMichel Lespinasse <walken@google.com>
Wed, 20 Dec 2017 17:02:12 +0000 (18:02 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 20 Dec 2017 17:02:12 +0000 (18:02 +0100)
commit344824c0f4b6aae3deca1e8b15d4e3f26a761682
treeb7f1c3fcf966f47ceab8ca75d4b083a63d99c9d1
parent33dcdc8ae0b35d9811126f8b7f5566bfde3295c8
rbtree: break out of rb_insert_color loop after tree rotation

It is a well known property of rbtrees that insertion never requires more
than two tree rotations.  In our implementation, after one loop iteration
identified one or two necessary tree rotations, we would iterate and look
for more.  However at that point the node's parent would always be black,
which would cause us to exit the loop.

We can make the code flow more obvious by just adding a break statement
after the tree rotations, where we know we are done.  Additionally, in the
cases where two tree rotations are necessary, we don't have to update the
'node' pointer as it wouldn't be used until the next loop iteration, which
we now avoid due to this break statement.

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 1f0528653e41ec230c60f5738820e8a544731399]

Ported to Xen.

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