summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2019-01-14 02:12:02 +0100
committerBenjamin Otte <otte@redhat.com>2019-01-14 02:14:11 +0100
commit8a7706f2b5cfc1dd7cdf0b8865fc05da0f4a6891 (patch)
treeb6f9107ae087bf55b10c5d53ea5ba9a14cc30dbf /gtk
parent6a3c2a230a4d1ef9f8c356cc5f24fbb202172e0c (diff)
downloadgtk+-8a7706f2b5cfc1dd7cdf0b8865fc05da0f4a6891.tar.gz
rbtree: Make node getters not require tree argument
The tree is not needed to walk around the nodes. It is however still needed for anything that requires modifying the tree. There is no immediate benefit in changing this API, but there might be situations in the future where we can avoid looking up the tree when we just want to check some details about the node.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkfilterlistmodel.c14
-rw-r--r--gtk/gtkflattenlistmodel.c16
-rw-r--r--gtk/gtkmaplistmodel.c20
-rw-r--r--gtk/gtkrbtree.c18
-rw-r--r--gtk/gtkrbtreeprivate.h22
-rw-r--r--gtk/gtktreelistmodel.c30
6 files changed, 54 insertions, 66 deletions
diff --git a/gtk/gtkfilterlistmodel.c b/gtk/gtkfilterlistmodel.c
index aa5abe8df2..8f515b5b9c 100644
--- a/gtk/gtkfilterlistmodel.c
+++ b/gtk/gtkfilterlistmodel.c
@@ -92,7 +92,7 @@ gtk_filter_list_model_get_nth_filtered (GtkRbTree *tree,
while (node)
{
- tmp = gtk_rb_tree_get_left (tree, node);
+ tmp = gtk_rb_tree_node_get_left (node);
if (tmp)
{
FilterAugment *aug = gtk_rb_tree_get_augment (tree, tmp);
@@ -114,7 +114,7 @@ gtk_filter_list_model_get_nth_filtered (GtkRbTree *tree,
unfiltered++;
- node = gtk_rb_tree_get_right (tree, node);
+ node = gtk_rb_tree_node_get_right (node);
}
if (out_unfiltered)
@@ -136,7 +136,7 @@ gtk_filter_list_model_get_nth (GtkRbTree *tree,
while (node)
{
- tmp = gtk_rb_tree_get_left (tree, node);
+ tmp = gtk_rb_tree_node_get_left (node);
if (tmp)
{
FilterAugment *aug = gtk_rb_tree_get_augment (tree, tmp);
@@ -156,7 +156,7 @@ gtk_filter_list_model_get_nth (GtkRbTree *tree,
if (node->visible)
filtered++;
- node = gtk_rb_tree_get_right (tree, node);
+ node = gtk_rb_tree_node_get_right (node);
}
if (out_filtered)
@@ -280,7 +280,7 @@ gtk_filter_list_model_items_changed_cb (GListModel *model,
filter_removed = 0;
for (i = 0; i < removed; i++)
{
- FilterNode *next = gtk_rb_tree_get_next (self->items, node);
+ FilterNode *next = gtk_rb_tree_node_get_next (node);
if (node->visible)
filter_removed++;
gtk_rb_tree_remove (self->items, node);
@@ -677,7 +677,7 @@ gtk_filter_list_model_refilter (GtkFilterListModel *self)
n_was_visible = 0;
for (i = 0, node = gtk_rb_tree_get_first (self->items);
node != NULL;
- i++, node = gtk_rb_tree_get_next (self->items, node))
+ i++, node = gtk_rb_tree_node_get_next (node))
{
visible = gtk_filter_list_model_run_filter (self, i);
if (visible == node->visible)
@@ -691,7 +691,7 @@ gtk_filter_list_model_refilter (GtkFilterListModel *self)
}
node->visible = visible;
- gtk_rb_tree_mark_dirty (self->items, node);
+ gtk_rb_tree_node_mark_dirty (node);
first_change = MIN (n_is_visible, first_change);
if (visible)
n_is_visible++;
diff --git a/gtk/gtkflattenlistmodel.c b/gtk/gtkflattenlistmodel.c
index 58852061e2..c8d5118c9b 100644
--- a/gtk/gtkflattenlistmodel.c
+++ b/gtk/gtkflattenlistmodel.c
@@ -88,7 +88,7 @@ gtk_flatten_list_model_get_nth (GtkRbTree *tree,
while (node)
{
- tmp = gtk_rb_tree_get_left (tree, node);
+ tmp = gtk_rb_tree_node_get_left (node);
if (tmp)
{
FlattenAugment *aug = gtk_rb_tree_get_augment (tree, tmp);
@@ -105,7 +105,7 @@ gtk_flatten_list_model_get_nth (GtkRbTree *tree,
break;
position -= model_n_items;
- node = gtk_rb_tree_get_right (tree, node);
+ node = gtk_rb_tree_node_get_right (node);
}
if (model_position)
@@ -127,7 +127,7 @@ gtk_flatten_list_model_get_nth_model (GtkRbTree *tree,
while (node)
{
- tmp = gtk_rb_tree_get_left (tree, node);
+ tmp = gtk_rb_tree_node_get_left (node);
if (tmp)
{
FlattenAugment *aug = gtk_rb_tree_get_augment (tree, tmp);
@@ -145,7 +145,7 @@ gtk_flatten_list_model_get_nth_model (GtkRbTree *tree,
position--;
before += g_list_model_get_n_items (node->model);
- node = gtk_rb_tree_get_right (tree, node);
+ node = gtk_rb_tree_node_get_right (node);
}
if (items_before)
@@ -220,13 +220,13 @@ gtk_flatten_list_model_items_changed_cb (GListModel *model,
GtkFlattenListModel *self = node->list;
guint real_position;
- gtk_rb_tree_mark_dirty (self->items, node);
+ gtk_rb_tree_node_mark_dirty (node);
for (real_position = position;
- (parent = gtk_rb_tree_get_parent (self->items, node)) != NULL;
+ (parent = gtk_rb_tree_node_get_parent (node)) != NULL;
node = parent)
{
- FlattenNode *left = gtk_rb_tree_get_left (self->items, parent);
+ FlattenNode *left = gtk_rb_tree_node_get_left (parent);
if (left != node)
{
if (left)
@@ -366,7 +366,7 @@ gtk_flatten_list_model_model_items_changed_cb (GListModel *model,
real_removed = 0;
for (i = 0; i < removed; i++)
{
- FlattenNode *next = gtk_rb_tree_get_next (self->items, node);
+ FlattenNode *next = gtk_rb_tree_node_get_next (node);
real_removed += g_list_model_get_n_items (node->model);
gtk_rb_tree_remove (self->items, node);
node = next;
diff --git a/gtk/gtkmaplistmodel.c b/gtk/gtkmaplistmodel.c
index 9be8aa7922..1fbf526f58 100644
--- a/gtk/gtkmaplistmodel.c
+++ b/gtk/gtkmaplistmodel.c
@@ -95,7 +95,7 @@ gtk_map_list_model_get_nth (GtkRbTree *tree,
while (node)
{
- tmp = gtk_rb_tree_get_left (tree, node);
+ tmp = gtk_rb_tree_node_get_left (node);
if (tmp)
{
MapAugment *aug = gtk_rb_tree_get_augment (tree, tmp);
@@ -114,7 +114,7 @@ gtk_map_list_model_get_nth (GtkRbTree *tree,
}
position -= node->n_items;
- node = gtk_rb_tree_get_right (tree, node);
+ node = gtk_rb_tree_node_get_right (node);
}
if (out_start_pos)
@@ -168,7 +168,7 @@ gtk_map_list_model_get_item (GListModel *list,
MapNode *before = gtk_rb_tree_insert_before (self->items, node);
before->n_items = position - offset;
node->n_items -= before->n_items;
- gtk_rb_tree_mark_dirty (self->items, node);
+ gtk_rb_tree_node_mark_dirty (node);
}
if (node->n_items > 1)
@@ -176,7 +176,7 @@ gtk_map_list_model_get_item (GListModel *list,
MapNode *after = gtk_rb_tree_insert_after (self->items, node);
after->n_items = node->n_items - 1;
node->n_items = 1;
- gtk_rb_tree_mark_dirty (self->items, node);
+ gtk_rb_tree_node_mark_dirty (node);
}
node->item = self->map_func (g_list_model_get_item (self->model, position), self->user_data);
@@ -225,7 +225,7 @@ gtk_map_list_model_items_changed_cb (GListModel *model,
end = start + node->n_items;
if (start == position && end <= position + removed)
{
- MapNode *next = gtk_rb_tree_get_next (self->items, node);
+ MapNode *next = gtk_rb_tree_node_get_next (node);
removed -= node->n_items;
gtk_rb_tree_remove (self->items, node);
node = next;
@@ -236,16 +236,16 @@ gtk_map_list_model_items_changed_cb (GListModel *model,
{
node->n_items -= removed;
removed = 0;
- gtk_rb_tree_mark_dirty (self->items, node);
+ gtk_rb_tree_node_mark_dirty (node);
}
else if (start < position)
{
guint overlap = node->n_items - (position - start);
node->n_items -= overlap;
- gtk_rb_tree_mark_dirty (self->items, node);
+ gtk_rb_tree_node_mark_dirty (node);
removed -= overlap;
start = position;
- node = gtk_rb_tree_get_next (self->items, node);
+ node = gtk_rb_tree_node_get_next (node);
}
}
}
@@ -258,7 +258,7 @@ gtk_map_list_model_items_changed_cb (GListModel *model,
node = gtk_rb_tree_insert_after (self->items, node);
node->n_items += added;
- gtk_rb_tree_mark_dirty (self->items, node);
+ gtk_rb_tree_node_mark_dirty (node);
}
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
@@ -489,7 +489,7 @@ gtk_map_list_model_init_items (GtkMapListModel *self)
{
MapNode *node = gtk_rb_tree_insert_before (self->items, NULL);
node->n_items = g_list_model_get_n_items (self->model);
- gtk_rb_tree_mark_dirty (self->items, node);
+ gtk_rb_tree_node_mark_dirty (node);
}
}
else
diff --git a/gtk/gtkrbtree.c b/gtk/gtkrbtree.c
index 14b017f181..4e52189233 100644
--- a/gtk/gtkrbtree.c
+++ b/gtk/gtkrbtree.c
@@ -536,15 +536,13 @@ gtk_rb_tree_get_last (GtkRbTree *tree)
}
gpointer
-gtk_rb_tree_get_previous (GtkRbTree *tree,
- gpointer node)
+gtk_rb_tree_node_get_previous (gpointer node)
{
return NODE_TO_POINTER (gtk_rb_node_get_previous (NODE_FROM_POINTER (node)));
}
gpointer
-gtk_rb_tree_get_next (GtkRbTree *tree,
- gpointer node)
+gtk_rb_tree_node_get_next (gpointer node)
{
return NODE_TO_POINTER (gtk_rb_node_get_next (NODE_FROM_POINTER (node)));
}
@@ -556,22 +554,19 @@ gtk_rb_tree_get_root (GtkRbTree *tree)
}
gpointer
-gtk_rb_tree_get_parent (GtkRbTree *tree,
- gpointer node)
+gtk_rb_tree_node_get_parent (gpointer node)
{
return NODE_TO_POINTER (parent (NODE_FROM_POINTER (node)));
}
gpointer
-gtk_rb_tree_get_left (GtkRbTree *tree,
- gpointer node)
+gtk_rb_tree_node_get_left (gpointer node)
{
return NODE_TO_POINTER (NODE_FROM_POINTER (node)->left);
}
gpointer
-gtk_rb_tree_get_right (GtkRbTree *tree,
- gpointer node)
+gtk_rb_tree_node_get_right (gpointer node)
{
return NODE_TO_POINTER (NODE_FROM_POINTER (node)->right);
}
@@ -594,8 +589,7 @@ gtk_rb_tree_node_get_tree (gpointer node)
}
void
-gtk_rb_tree_mark_dirty (GtkRbTree *tree,
- gpointer node)
+gtk_rb_tree_node_mark_dirty (gpointer node)
{
gtk_rb_node_mark_dirty (NODE_FROM_POINTER (node), TRUE);
}
diff --git a/gtk/gtkrbtreeprivate.h b/gtk/gtkrbtreeprivate.h
index 8e74c5e19e..45aba5cc2d 100644
--- a/gtk/gtkrbtreeprivate.h
+++ b/gtk/gtkrbtreeprivate.h
@@ -45,25 +45,19 @@ GtkRbTree * gtk_rb_tree_new_for_size (gsize
GtkRbTree * gtk_rb_tree_ref (GtkRbTree *tree);
void gtk_rb_tree_unref (GtkRbTree *tree);
+gpointer gtk_rb_tree_get_root (GtkRbTree *tree);
gpointer gtk_rb_tree_get_first (GtkRbTree *tree);
gpointer gtk_rb_tree_get_last (GtkRbTree *tree);
-gpointer gtk_rb_tree_get_previous (GtkRbTree *tree,
- gpointer node);
-gpointer gtk_rb_tree_get_next (GtkRbTree *tree,
- gpointer node);
-gpointer gtk_rb_tree_get_root (GtkRbTree *tree);
-gpointer gtk_rb_tree_get_parent (GtkRbTree *tree,
- gpointer node);
-gpointer gtk_rb_tree_get_left (GtkRbTree *tree,
- gpointer node);
-gpointer gtk_rb_tree_get_right (GtkRbTree *tree,
- gpointer node);
-gpointer gtk_rb_tree_get_augment (GtkRbTree *tree,
- gpointer node);
+gpointer gtk_rb_tree_node_get_previous (gpointer node);
+gpointer gtk_rb_tree_node_get_next (gpointer node);
+gpointer gtk_rb_tree_node_get_parent (gpointer node);
+gpointer gtk_rb_tree_node_get_left (gpointer node);
+gpointer gtk_rb_tree_node_get_right (gpointer node);
GtkRbTree * gtk_rb_tree_node_get_tree (gpointer node);
+void gtk_rb_tree_node_mark_dirty (gpointer node);
-void gtk_rb_tree_mark_dirty (GtkRbTree *tree,
+gpointer gtk_rb_tree_get_augment (GtkRbTree *tree,
gpointer node);
gpointer gtk_rb_tree_insert_before (GtkRbTree *tree,
diff --git a/gtk/gtktreelistmodel.c b/gtk/gtktreelistmodel.c
index af609e61ce..f74d61f6d9 100644
--- a/gtk/gtktreelistmodel.c
+++ b/gtk/gtktreelistmodel.c
@@ -121,7 +121,7 @@ tree_node_get_nth_child (TreeNode *node,
while (child)
{
- tmp = gtk_rb_tree_get_left (tree, child);
+ tmp = gtk_rb_tree_node_get_left (child);
if (tmp)
{
aug = gtk_rb_tree_get_augment (tree, tmp);
@@ -138,7 +138,7 @@ tree_node_get_nth_child (TreeNode *node,
position--;
- child = gtk_rb_tree_get_right (tree, child);
+ child = gtk_rb_tree_node_get_right (child);
}
return NULL;
@@ -170,7 +170,7 @@ tree_node_get_local_position (GtkRbTree *tree,
TreeAugment *left_aug;
guint n;
- left = gtk_rb_tree_get_left (tree, node);
+ left = gtk_rb_tree_node_get_left (node);
if (left)
{
left_aug = gtk_rb_tree_get_augment (tree, left);
@@ -181,11 +181,11 @@ tree_node_get_local_position (GtkRbTree *tree,
n = 0;
}
- for (parent = gtk_rb_tree_get_parent (tree, node);
+ for (parent = gtk_rb_tree_node_get_parent (node);
parent;
- parent = gtk_rb_tree_get_parent (tree, node))
+ parent = gtk_rb_tree_node_get_parent (node))
{
- left = gtk_rb_tree_get_left (tree, parent);
+ left = gtk_rb_tree_node_get_left (parent);
if (left == node)
{
/* we are the left node, nothing changes */
@@ -220,18 +220,18 @@ tree_node_get_position (TreeNode *node)
{
tree = node->parent->children;
- left = gtk_rb_tree_get_left (tree, node);
+ left = gtk_rb_tree_node_get_left (node);
if (left)
{
left_aug = gtk_rb_tree_get_augment (tree, left);
n += left_aug->n_items;
}
- for (parent = gtk_rb_tree_get_parent (tree, node);
+ for (parent = gtk_rb_tree_node_get_parent (node);
parent;
- parent = gtk_rb_tree_get_parent (tree, node))
+ parent = gtk_rb_tree_node_get_parent (node))
{
- left = gtk_rb_tree_get_left (tree, parent);
+ left = gtk_rb_tree_node_get_left (parent);
if (left == node)
{
/* we are the left node, nothing changes */
@@ -262,7 +262,7 @@ tree_node_mark_dirty (TreeNode *node)
!node->is_root;
node = node->parent)
{
- gtk_rb_tree_mark_dirty (node->parent->children, node);
+ gtk_rb_tree_node_mark_dirty (node);
}
}
@@ -283,7 +283,7 @@ gtk_tree_list_model_get_nth (GtkTreeListModel *self,
while (TRUE)
{
- tmp = gtk_rb_tree_get_left (tree, node);
+ tmp = gtk_rb_tree_node_get_left (node);
if (tmp)
{
TreeAugment *aug = gtk_rb_tree_get_augment (tree, tmp);
@@ -309,7 +309,7 @@ gtk_tree_list_model_get_nth (GtkTreeListModel *self,
}
position -= n_children;
- node = gtk_rb_tree_get_right (tree, node);
+ node = gtk_rb_tree_node_get_right (node);
}
g_return_val_if_reached (NULL);
@@ -406,7 +406,7 @@ gtk_tree_list_model_items_changed_cb (GListModel *model,
for (i = 0; i < removed; i++)
{
tmp = child;
- child = gtk_rb_tree_get_next (node->children, child);
+ child = gtk_rb_tree_node_get_next (child);
gtk_rb_tree_remove (node->children, tmp);
}
}
@@ -426,7 +426,7 @@ gtk_tree_list_model_items_changed_cb (GListModel *model,
for (i = 0; i < added; i++)
{
tree_added += gtk_tree_list_model_expand_node (self, child);
- child = gtk_rb_tree_get_next (node->children, child);
+ child = gtk_rb_tree_node_get_next (child);
}
}