]> git.kaiwu.me - njs.git/commitdiff
A small rbtree insert fixup optimization.
authorIgor Sysoev <igor@sysoev.ru>
Fri, 20 Jan 2017 13:10:48 +0000 (16:10 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 20 Jan 2017 13:10:48 +0000 (16:10 +0300)
Thanks to 洪志道 (Hong Zhi Dao).

nxt/nxt_rbtree.c

index 24cb4e6f65b29f6a7d4f81ca2533ca0c4482d33d..852317d4f772565107ff305e92dbdb9d0283110c 100644 (file)
@@ -135,8 +135,12 @@ nxt_rbtree_insert_fixup(nxt_rbtree_node_t *node)
                 grandparent = parent->parent;
                 grandparent->color = NXT_RBTREE_RED;
                 nxt_rbtree_right_rotate(grandparent);
-
-                continue;
+                /*
+                 * nxt_rbtree_right_rotate() does not change node->parent
+                 * color which is now black, so testing color is not required
+                 * to return from function.
+                 */
+                return;
             }
 
         } else {
@@ -156,7 +160,8 @@ nxt_rbtree_insert_fixup(nxt_rbtree_node_t *node)
                 grandparent->color = NXT_RBTREE_RED;
                 nxt_rbtree_left_rotate(grandparent);
 
-                continue;
+                /* See the comment in the symmetric branch above. */
+                return;
             }
         }