Commit c3056951 authored by Benjamin Otte's avatar Benjamin Otte

rbtree: Introduce _gtk_rbtree_first()

... and use it.
parent 73a83433
......@@ -722,11 +722,8 @@ _gtk_rbtree_column_invalid (GtkRBTree *tree)
if (tree == NULL)
return;
node = tree->root;
g_assert (node);
while (node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
do
{
......@@ -747,11 +744,8 @@ _gtk_rbtree_mark_invalid (GtkRBTree *tree)
if (tree == NULL)
return;
node = tree->root;
g_assert (node);
while (node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
do
{
......@@ -774,11 +768,7 @@ _gtk_rbtree_set_fixed_height (GtkRBTree *tree,
if (tree == NULL)
return;
node = tree->root;
g_assert (node);
while (node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
do
{
......@@ -888,9 +878,7 @@ _gtk_rbtree_reorder (GtkRBTree *tree,
g_array_sort(array, gtk_rbtree_reorder_sort_func);
/* rewind node*/
node = tree->root;
while (node && node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
for (i = 0; i < length; i++)
{
......@@ -905,9 +893,7 @@ _gtk_rbtree_reorder (GtkRBTree *tree,
g_array_sort (array, gtk_rbtree_reorder_invert_func);
/* rewind node*/
node = tree->root;
while (node && node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
/* Go through the tree and change the values to the new ones. */
for (i = 0; i < length; i++)
......@@ -1259,6 +1245,22 @@ _gtk_rbtree_remove_node (GtkRBTree *tree,
#endif /* G_ENABLE_DEBUG */
}
GtkRBNode *
_gtk_rbtree_first (GtkRBTree *tree)
{
GtkRBNode *node;
node = tree->root;
if (node == tree->nil)
return NULL;
while (node->left != tree->nil)
node = node->left;
return node;
}
GtkRBNode *
_gtk_rbtree_next (GtkRBTree *tree,
GtkRBNode *node)
......
......@@ -148,6 +148,7 @@ void _gtk_rbtree_traverse (GtkRBTree *tree,
GTraverseType order,
GtkRBTreeTraverseFunc func,
gpointer data);
GtkRBNode *_gtk_rbtree_first (GtkRBTree *tree);
GtkRBNode *_gtk_rbtree_next (GtkRBTree *tree,
GtkRBNode *node);
GtkRBNode *_gtk_rbtree_prev (GtkRBTree *tree,
......
......@@ -605,10 +605,7 @@ gtk_tree_selection_get_selected_rows (GtkTreeSelection *selection,
return NULL;
}
node = tree->root;
while (node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
path = gtk_tree_path_new_first ();
do
......@@ -619,10 +616,7 @@ gtk_tree_selection_get_selected_rows (GtkTreeSelection *selection,
if (node->children)
{
tree = node->children;
node = tree->root;
while (node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
gtk_tree_path_append_index (path, 0);
}
......@@ -786,10 +780,7 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
return;
}
node = tree->root;
while (node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
g_object_ref (model);
......@@ -824,10 +815,7 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,
if (node->children)
{
tree = node->children;
node = tree->root;
while (node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
gtk_tree_path_append_index (path, 0);
}
......@@ -1377,9 +1365,7 @@ gtk_tree_selection_real_modify_range (GtkTreeSelection *selection,
if (start_node->children)
{
start_tree = start_node->children;
start_node = start_tree->root;
while (start_node->left != start_tree->nil)
start_node = start_node->left;
start_node = _gtk_rbtree_first (start_tree);
}
else
{
......
......@@ -4233,9 +4233,7 @@ skip_first:
if (start_node->children)
{
start_tree = start_node->children;
start_node = start_tree->root;
while (start_node->left != start_tree->nil)
start_node = start_node->left;
start_node = _gtk_rbtree_first (start_tree);
}
else
{
......@@ -5270,12 +5268,8 @@ gtk_tree_view_bin_draw (GtkWidget *widget,
gboolean has_child;
tree = node->children;
node = tree->root;
node = _gtk_rbtree_first (tree);
g_assert (node != tree->nil);
while (node->left != tree->nil)
node = node->left;
has_child = gtk_tree_model_iter_children (tree_view->priv->model,
&iter,
&parent);
......@@ -6371,12 +6365,8 @@ validate_visible_area (GtkTreeView *tree_view)
gboolean has_child;
tree = node->children;
node = tree->root;
g_assert (node != tree->nil);
node = _gtk_rbtree_first (tree);
while (node->left != tree->nil)
node = node->left;
has_child = gtk_tree_model_iter_children (tree_view->priv->model,
&iter,
&parent);
......@@ -9579,10 +9569,7 @@ gtk_tree_view_unref_tree_helper (GtkTreeModel *model,
GtkRBNode *new_node;
new_tree = node->children;
new_node = new_tree->root;
while (new_node && new_node->left != new_tree->nil)
new_node = new_node->left;
new_node = _gtk_rbtree_first (new_tree);
if (!gtk_tree_model_iter_children (model, &child, iter))
return FALSE;
......@@ -9612,9 +9599,7 @@ gtk_tree_view_unref_and_check_selection_tree (GtkTreeView *tree_view,
if (!tree)
return FALSE;
node = tree->root;
while (node && node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
g_return_val_if_fail (node != NULL, FALSE);
path = _gtk_tree_view_find_path (tree_view, tree, node);
......@@ -10553,12 +10538,10 @@ gtk_tree_view_move_cursor_start_end (GtkTreeView *tree_view,
gtk_tree_view_get_cursor (tree_view, &old_path, NULL);
cursor_tree = tree_view->priv->tree;
cursor_node = cursor_tree->root;
if (count == -1)
{
while (cursor_node && cursor_node->left != cursor_tree->nil)
cursor_node = cursor_node->left;
cursor_node = _gtk_rbtree_first (cursor_tree);
/* Now go forward to find the first focusable row. */
path = _gtk_tree_view_find_path (tree_view, cursor_tree, cursor_node);
......@@ -10567,6 +10550,8 @@ gtk_tree_view_move_cursor_start_end (GtkTreeView *tree_view,
}
else
{
cursor_node = cursor_tree->root;
do
{
while (cursor_node && cursor_node->right != cursor_tree->nil)
......@@ -12623,9 +12608,7 @@ gtk_tree_view_collapse_all (GtkTreeView *tree_view)
indices = gtk_tree_path_get_indices (path);
tree = tree_view->priv->tree;
node = tree->root;
while (node && node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
while (node)
{
......@@ -12717,9 +12700,7 @@ gtk_tree_view_real_expand_row (GtkTreeView *tree_view,
gtk_tree_path_append_index (tmp_path, 0);
tree = node->children;
node = tree->root;
while (node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
/* try to expand the children */
do
{
......@@ -13037,10 +13018,7 @@ gtk_tree_view_map_expanded_rows_helper (GtkTreeView *tree_view,
if (tree == NULL || tree->root == NULL)
return;
node = tree->root;
while (node && node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
while (node)
{
......@@ -15449,10 +15427,7 @@ gtk_tree_view_search_iter (GtkTreeModel *model,
GtkTreeIter tmp;
tree = node->children;
node = tree->root;
while (node->left != tree->nil)
node = node->left;
node = _gtk_rbtree_first (tree);
tmp = *iter;
has_child = gtk_tree_model_iter_children (model, iter, &tmp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment