diff mbox

[v5,02/17] rbtree: remove redundant if()-condition in rb_erase()

Message ID 20170714082636.29511-3-kpraveen.lkml@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Praveen Kumar July 14, 2017, 8:26 a.m. UTC
From: Wolfram Strepp <wstrepp@gmx.de>

Furthermore, notice that the initial checks:

            if (!node->rb_left)
                    child = node->rb_right;
            else if (!node->rb_right)
                    child = node->rb_left;
            else
            {
                    ...
            }
guarantee that old->rb_right is set in the final else branch, therefore
we can omit checking that again.

Signed-off-by: Wolfram Strepp <wstrepp@gmx.de>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[Linux commit 4b324126e0c6c3a5080ca3ec0981e8766ed6f1ee]

Ported to Xen.

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

Comments

Jan Beulich Aug. 3, 2017, 10:11 a.m. UTC | #1
>>> On 14.07.17 at 10:26, <kpraveen.lkml@gmail.com> wrote:
> --- a/xen/common/rbtree.c
> +++ b/xen/common/rbtree.c
> @@ -250,15 +250,16 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
>  			if (child)
>  				rb_set_parent(child, parent);
>  			parent->rb_left = child;
> +
> +			node->rb_right = old->rb_right;
> +			rb_set_parent(old->rb_right, node);
>  		}
>  
>  		node->rb_parent_color = old->rb_parent_color;
> -		node->rb_right = old->rb_right;
>  		node->rb_left = old->rb_left;
>  
>  		rb_set_parent(old->rb_left, node);

The original Linux commit also removes the blank line above. Once
again, for ease of future patch application, please _do not_ alter
the original commits unless you really can't avoid it.

Jan
diff mbox

Patch

diff --git a/xen/common/rbtree.c b/xen/common/rbtree.c
index 167ebfdc4d..acfd34a62d 100644
--- a/xen/common/rbtree.c
+++ b/xen/common/rbtree.c
@@ -250,15 +250,16 @@  void rb_erase(struct rb_node *node, struct rb_root *root)
 			if (child)
 				rb_set_parent(child, parent);
 			parent->rb_left = child;
+
+			node->rb_right = old->rb_right;
+			rb_set_parent(old->rb_right, node);
 		}
 
 		node->rb_parent_color = old->rb_parent_color;
-		node->rb_right = old->rb_right;
 		node->rb_left = old->rb_left;
 
 		rb_set_parent(old->rb_left, node);
-		if (old->rb_right)
-			rb_set_parent(old->rb_right, node);
+
 		goto color;
 	}