Skip to contentSkip to conversation

rb_tree: remove redundant if()-condition in rb_erase()

PATCH New Wolfram Strepp 1 participant 1 message Apr 11, 2009 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 rb_tree: remove redundant if()-condition in rb_erase()

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.

---
 lib/rbtree.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/rbtree.c +4 -4
Index: linux-2.6/lib/rbtree.c
===================================================================
@@ -257,15 +257,15 @@ void rb_erase(struct rb_node *node, stru
 			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;
 	}
 
Signature · 1 line
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01