[njs] A small rbtree insert fixup optimization.

Igor Sysoev igor at sysoev.ru
Fri Jan 20 13:11:23 UTC 2017


details:   http://hg.nginx.org/njs/rev/8401ae77cf40
branches:  
changeset: 303:8401ae77cf40
user:      Igor Sysoev <igor at sysoev.ru>
date:      Fri Jan 20 16:10:48 2017 +0300
description:
A small rbtree insert fixup optimization.

Thanks to ??? (Hong Zhi Dao).

diffstat:

 nxt/nxt_rbtree.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r 5db6d7af16b4 -r 8401ae77cf40 nxt/nxt_rbtree.c
--- a/nxt/nxt_rbtree.c	Mon Jan 16 18:14:01 2017 +0300
+++ b/nxt/nxt_rbtree.c	Fri Jan 20 16:10:48 2017 +0300
@@ -135,8 +135,12 @@ nxt_rbtree_insert_fixup(nxt_rbtree_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_
                 grandparent->color = NXT_RBTREE_RED;
                 nxt_rbtree_left_rotate(grandparent);
 
-                continue;
+                /* See the comment in the symmetric branch above. */
+                return;
             }
         }
 


More information about the nginx-devel mailing list