diff options
-rw-r--r-- | lib/rbtree.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/rbtree.c b/lib/rbtree.c index d102d9d2ffaa..e7cce12f404f 100644 --- a/lib/rbtree.c +++ b/lib/rbtree.c | |||
@@ -105,16 +105,25 @@ __rb_insert(struct rb_node *node, struct rb_root *root, | |||
105 | 105 | ||
106 | while (true) { | 106 | while (true) { |
107 | /* | 107 | /* |
108 | * Loop invariant: node is red | 108 | * Loop invariant: node is red. |
109 | * | ||
110 | * If there is a black parent, we are done. | ||
111 | * Otherwise, take some corrective action as we don't | ||
112 | * want a red root or two consecutive red nodes. | ||
113 | */ | 109 | */ |
114 | if (!parent) { | 110 | if (unlikely(!parent)) { |
111 | /* | ||
112 | * The inserted node is root. Either this is the | ||
113 | * first node, or we recursed at Case 1 below and | ||
114 | * are no longer violating 4). | ||
115 | */ | ||
115 | rb_set_parent_color(node, NULL, RB_BLACK); | 116 | rb_set_parent_color(node, NULL, RB_BLACK); |
116 | break; | 117 | break; |
117 | } else if (rb_is_black(parent)) | 118 | } |
119 | |||
120 | /* | ||
121 | * If there is a black parent, we are done. | ||
122 | * Otherwise, take some corrective action as, | ||
123 | * per 4), we don't want a red root or two | ||
124 | * consecutive red nodes. | ||
125 | */ | ||
126 | if(rb_is_black(parent)) | ||
118 | break; | 127 | break; |
119 | 128 | ||
120 | gparent = rb_red_parent(parent); | 129 | gparent = rb_red_parent(parent); |