]> git.kaiwu.me - njs.git/commitdiff
A small rbtree delete fixup optimization.
authorIgor Sysoev <igor@sysoev.ru>
Mon, 29 May 2017 07:17:36 +0000 (10:17 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 29 May 2017 07:17:36 +0000 (10:17 +0300)
Setting node color to black is not required here because
it is already black.  Besides in the original algorithm
the node pointer is discarded and the node is set to tree
root just to quit the loop.

Thanks to 洪志道 (Hong Zhi Dao).

nxt/nxt_rbtree.c

index 6b5cd1be06fa2e02075026121ccf05f59b36c045..390464f68ec84be1625d9cf91526fe52c217e04d 100644 (file)
@@ -402,7 +402,7 @@ nxt_rbtree_delete_fixup(nxt_rbtree_t *tree, nxt_rbtree_node_t *node)
 
             nxt_rbtree_left_rotate(parent);
 
-            break;
+            return;
 
         } else {
             sibling = parent->left;
@@ -440,7 +440,7 @@ nxt_rbtree_delete_fixup(nxt_rbtree_t *tree, nxt_rbtree_node_t *node)
 
             nxt_rbtree_right_rotate(parent);
 
-            break;
+            return;
         }
     }