diff options
author | Wolfram Strepp <wstrepp@gmx.de> | 2009-03-31 18:23:45 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-04-01 11:59:17 -0400 |
commit | 55a63998b8967615a15e2211ba0ff3a84a565824 (patch) | |
tree | a83905577b60496a3ea9174bf29596f927354746 | |
parent | 53d6660836f233df66490707365ab177e5fb2bb4 (diff) |
lib/rbtree.c: optimize rb_erase()
Tfour 4 redundant if-conditions in function __rb_erase_color() in
lib/rbtree.c are removed.
In pseudo-source-code, the structure of the code is as follows:
if ((!A || B) && (!C || D)) {
.
.
.
} else {
if (!C || D) {//if this is true, it implies: (A == true) && (B == false)
if (A) {//hence this always evaluates to 'true'...
.
}
.
//at this point, C always becomes true, because of:
__rb_rotate_right/left();
//and:
other = parent->rb_right/left;
}
.
.
if (C) {//...and this too !
.
}
}
Signed-off-by: Wolfram Strepp <wstrepp@gmx.de>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Andrea Arcangeli <andrea@qumranet.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | lib/rbtree.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/lib/rbtree.c b/lib/rbtree.c index 9956b99649f0..f653659e0bc1 100644 --- a/lib/rbtree.c +++ b/lib/rbtree.c | |||
@@ -163,17 +163,14 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, | |||
163 | { | 163 | { |
164 | if (!other->rb_right || rb_is_black(other->rb_right)) | 164 | if (!other->rb_right || rb_is_black(other->rb_right)) |
165 | { | 165 | { |
166 | struct rb_node *o_left; | 166 | rb_set_black(other->rb_left); |
167 | if ((o_left = other->rb_left)) | ||
168 | rb_set_black(o_left); | ||
169 | rb_set_red(other); | 167 | rb_set_red(other); |
170 | __rb_rotate_right(other, root); | 168 | __rb_rotate_right(other, root); |
171 | other = parent->rb_right; | 169 | other = parent->rb_right; |
172 | } | 170 | } |
173 | rb_set_color(other, rb_color(parent)); | 171 | rb_set_color(other, rb_color(parent)); |
174 | rb_set_black(parent); | 172 | rb_set_black(parent); |
175 | if (other->rb_right) | 173 | rb_set_black(other->rb_right); |
176 | rb_set_black(other->rb_right); | ||
177 | __rb_rotate_left(parent, root); | 174 | __rb_rotate_left(parent, root); |
178 | node = root->rb_node; | 175 | node = root->rb_node; |
179 | break; | 176 | break; |
@@ -200,17 +197,14 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, | |||
200 | { | 197 | { |
201 | if (!other->rb_left || rb_is_black(other->rb_left)) | 198 | if (!other->rb_left || rb_is_black(other->rb_left)) |
202 | { | 199 | { |
203 | register struct rb_node *o_right; | 200 | rb_set_black(other->rb_right); |
204 | if ((o_right = other->rb_right)) | ||
205 | rb_set_black(o_right); | ||
206 | rb_set_red(other); | 201 | rb_set_red(other); |
207 | __rb_rotate_left(other, root); | 202 | __rb_rotate_left(other, root); |
208 | other = parent->rb_left; | 203 | other = parent->rb_left; |
209 | } | 204 | } |
210 | rb_set_color(other, rb_color(parent)); | 205 | rb_set_color(other, rb_color(parent)); |
211 | rb_set_black(parent); | 206 | rb_set_black(parent); |
212 | if (other->rb_left) | 207 | rb_set_black(other->rb_left); |
213 | rb_set_black(other->rb_left); | ||
214 | __rb_rotate_right(parent, root); | 208 | __rb_rotate_right(parent, root); |
215 | node = root->rb_node; | 209 | node = root->rb_node; |
216 | break; | 210 | break; |