From c1efa5e66158d6dc816523a908a030731a0ec330 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Fri, 20 Jan 2017 16:10:48 +0300 Subject: [PATCH] A small rbtree insert fixup optimization. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Thanks to 洪志道 (Hong Zhi Dao). --- nxt/nxt_rbtree.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nxt/nxt_rbtree.c b/nxt/nxt_rbtree.c index 24cb4e6f..852317d4 100644 --- a/nxt/nxt_rbtree.c +++ b/nxt/nxt_rbtree.c @@ -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; } } -- 2.47.3