From: Michel Lespinasse <wal...@google.com>

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 <wal...@google.com>
Cc: Andrea Arcangeli <aarca...@redhat.com>
Acked-by: David Woodhouse <david.woodho...@intel.com>
Cc: Rik van Riel <r...@redhat.com>
Cc: Peter Zijlstra <a.p.zijls...@chello.nl>
Cc: Daniel Santos <daniel.san...@pobox.com>
Cc: Jens Axboe <ax...@kernel.dk>
Cc: "Eric W. Biederman" <ebied...@xmission.com>
Signed-off-by: Andrew Morton <a...@linux-foundation.org>
Signed-off-by: Linus Torvalds <torva...@linux-foundation.org>
[Linux commit 1f0528653e41ec230c60f5738820e8a544731399]

Ported to Xen.

Signed-off-by: Praveen Kumar <kpraveen.l...@gmail.com>
---
 xen/common/rbtree.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/xen/common/rbtree.c b/xen/common/rbtree.c
index a75b336ba2..9dc296e0d8 100644
--- a/xen/common/rbtree.c
+++ b/xen/common/rbtree.c
@@ -109,18 +109,15 @@ void rb_insert_color(struct rb_node *node, struct rb_root 
*root)
                                }
                        }
 
-                       if (parent->rb_right == node)
-                       {
-                               register struct rb_node *tmp;
+                       if (parent->rb_right == node) {
                                __rb_rotate_left(parent, root);
-                               tmp = parent;
                                parent = node;
-                               node = tmp;
                        }
 
                        rb_set_black(parent);
                        rb_set_red(gparent);
                        __rb_rotate_right(gparent, root);
+                       break;
                } else {
                        {
                                register struct rb_node *uncle = 
gparent->rb_left;
@@ -134,18 +131,15 @@ void rb_insert_color(struct rb_node *node, struct rb_root 
*root)
                                }
                        }
 
-                       if (parent->rb_left == node)
-                       {
-                               register struct rb_node *tmp;
+                       if (parent->rb_left == node) {
                                __rb_rotate_right(parent, root);
-                               tmp = parent;
                                parent = node;
-                               node = tmp;
                        }
 
                        rb_set_black(parent);
                        rb_set_red(gparent);
                        __rb_rotate_left(gparent, root);
+                       break;
                }
        }
 
-- 
2.13.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

Reply via email to