[gtk+] rbtree: Add a local variable
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] rbtree: Add a local variable
- Date: Mon, 21 Nov 2011 21:36:57 +0000 (UTC)
commit f4fe921a174897844ec7f2896597f60b0a206903
Author: Benjamin Otte <otte redhat com>
Date: Mon Nov 21 22:28:36 2011 +0100
rbtree: Add a local variable
This will be needed in the next patch, and I wanted to split that patch
up.
gtk/gtkrbtree.c | 42 +++++++++++++++++++++++-------------------
1 files changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkrbtree.c b/gtk/gtkrbtree.c
index d327268..1b6f029 100644
--- a/gtk/gtkrbtree.c
+++ b/gtk/gtkrbtree.c
@@ -266,22 +266,24 @@ static void
_gtk_rbtree_remove_node_fixup (GtkRBTree *tree,
GtkRBNode *node)
{
+ GtkRBNode *parent = node->parent;
+
while (node != tree->root && GTK_RBNODE_GET_COLOR (node) == GTK_RBNODE_BLACK)
{
- if (node == node->parent->left)
+ if (node == parent->left)
{
- GtkRBNode *w = node->parent->right;
+ GtkRBNode *w = parent->right;
if (GTK_RBNODE_GET_COLOR (w) == GTK_RBNODE_RED)
{
GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_BLACK);
- GTK_RBNODE_SET_COLOR (node->parent, GTK_RBNODE_RED);
- _gtk_rbnode_rotate_left (tree, node->parent);
- w = node->parent->right;
+ GTK_RBNODE_SET_COLOR (parent, GTK_RBNODE_RED);
+ _gtk_rbnode_rotate_left (tree, parent);
+ w = parent->right;
}
if (GTK_RBNODE_GET_COLOR (w->left) == GTK_RBNODE_BLACK && GTK_RBNODE_GET_COLOR (w->right) == GTK_RBNODE_BLACK)
{
GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_RED);
- node = node->parent;
+ node = parent;
}
else
{
@@ -290,29 +292,29 @@ _gtk_rbtree_remove_node_fixup (GtkRBTree *tree,
GTK_RBNODE_SET_COLOR (w->left, GTK_RBNODE_BLACK);
GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_RED);
_gtk_rbnode_rotate_right (tree, w);
- w = node->parent->right;
+ w = parent->right;
}
- GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_GET_COLOR (node->parent));
- GTK_RBNODE_SET_COLOR (node->parent, GTK_RBNODE_BLACK);
+ GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_GET_COLOR (parent));
+ GTK_RBNODE_SET_COLOR (parent, GTK_RBNODE_BLACK);
GTK_RBNODE_SET_COLOR (w->right, GTK_RBNODE_BLACK);
- _gtk_rbnode_rotate_left (tree, node->parent);
+ _gtk_rbnode_rotate_left (tree, parent);
node = tree->root;
}
}
else
{
- GtkRBNode *w = node->parent->left;
+ GtkRBNode *w = parent->left;
if (GTK_RBNODE_GET_COLOR (w) == GTK_RBNODE_RED)
{
GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_BLACK);
- GTK_RBNODE_SET_COLOR (node->parent, GTK_RBNODE_RED);
- _gtk_rbnode_rotate_right (tree, node->parent);
- w = node->parent->left;
+ GTK_RBNODE_SET_COLOR (parent, GTK_RBNODE_RED);
+ _gtk_rbnode_rotate_right (tree, parent);
+ w = parent->left;
}
if (GTK_RBNODE_GET_COLOR (w->right) == GTK_RBNODE_BLACK && GTK_RBNODE_GET_COLOR (w->left) == GTK_RBNODE_BLACK)
{
GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_RED);
- node = node->parent;
+ node = parent;
}
else
{
@@ -321,15 +323,17 @@ _gtk_rbtree_remove_node_fixup (GtkRBTree *tree,
GTK_RBNODE_SET_COLOR (w->right, GTK_RBNODE_BLACK);
GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_RED);
_gtk_rbnode_rotate_left (tree, w);
- w = node->parent->left;
+ w = parent->left;
}
- GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_GET_COLOR (node->parent));
- GTK_RBNODE_SET_COLOR (node->parent, GTK_RBNODE_BLACK);
+ GTK_RBNODE_SET_COLOR (w, GTK_RBNODE_GET_COLOR (parent));
+ GTK_RBNODE_SET_COLOR (parent, GTK_RBNODE_BLACK);
GTK_RBNODE_SET_COLOR (w->left, GTK_RBNODE_BLACK);
- _gtk_rbnode_rotate_right (tree, node->parent);
+ _gtk_rbnode_rotate_right (tree, parent);
node = tree->root;
}
}
+
+ parent = node->parent;
}
GTK_RBNODE_SET_COLOR (node, GTK_RBNODE_BLACK);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]