mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-24 12:41:16 +00:00
gdkarray: Add a "stolen" boolean to splice()
If set to TRUE, does not call the free func for the removed items. This can be used to move items between arrays without having to do the refcounting dance.
This commit is contained in:
parent
71e616d17e
commit
96e1b85c2c
@ -182,6 +182,7 @@ G_GNUC_UNUSED static inline void
|
||||
gdk_array(splice) (GdkArray *self,
|
||||
gsize pos,
|
||||
gsize removed,
|
||||
gboolean stolen,
|
||||
_T_ *additions,
|
||||
gsize added)
|
||||
{
|
||||
@ -192,8 +193,9 @@ gdk_array(splice) (GdkArray *self,
|
||||
g_assert (pos + removed <= size);
|
||||
remaining = size - pos - removed;
|
||||
|
||||
gdk_array(free_elements) (gdk_array(index) (self, pos),
|
||||
gdk_array(index) (self, pos + removed));
|
||||
if (!stolen)
|
||||
gdk_array(free_elements) (gdk_array(index) (self, pos),
|
||||
gdk_array(index) (self, pos + removed));
|
||||
|
||||
gdk_array(reserve) (self, size - removed + added);
|
||||
|
||||
@ -225,9 +227,9 @@ gdk_array(set_size) (GdkArray *self,
|
||||
{
|
||||
gsize old_size = gdk_array(get_size) (self);
|
||||
if (new_size > old_size)
|
||||
gdk_array(splice) (self, old_size, 0, NULL, new_size - old_size);
|
||||
gdk_array(splice) (self, old_size, 0, FALSE, NULL, new_size - old_size);
|
||||
else
|
||||
gdk_array(splice) (self, new_size, old_size - new_size, NULL, 0);
|
||||
gdk_array(splice) (self, new_size, old_size - new_size, FALSE, NULL, 0);
|
||||
}
|
||||
|
||||
G_GNUC_UNUSED static void
|
||||
@ -241,6 +243,7 @@ gdk_array(append) (GdkArray *self,
|
||||
gdk_array(splice) (self,
|
||||
gdk_array(get_size) (self),
|
||||
0,
|
||||
FALSE,
|
||||
#ifdef GDK_ARRAY_BY_VALUE
|
||||
value,
|
||||
#else
|
||||
|
@ -100,7 +100,7 @@ gtk_accels_remove (GtkAccels *accels,
|
||||
|
||||
position = gtk_accels_find (accels, action_and_target);
|
||||
if (position < gtk_accels_get_size (accels))
|
||||
gtk_accels_splice (accels, position, 1, NULL, 0);
|
||||
gtk_accels_splice (accels, position, 1, FALSE, NULL, 0);
|
||||
}
|
||||
|
||||
/*< private >
|
||||
|
@ -167,7 +167,7 @@ gtk_css_selector_matches_insert_sorted (GtkCssSelectorMatches *matches,
|
||||
break;
|
||||
}
|
||||
|
||||
gtk_css_selector_matches_splice (matches, i, 0, (gpointer[1]) { data }, 1);
|
||||
gtk_css_selector_matches_splice (matches, i, 0, FALSE, (gpointer[1]) { data }, 1);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
|
@ -206,7 +206,7 @@ gtk_multi_filter_remove (GtkMultiFilter *self,
|
||||
|
||||
filter = gtk_filters_get (&self->filters, position);
|
||||
g_signal_handlers_disconnect_by_func (filter, gtk_multi_filter_changed_cb, self);
|
||||
gtk_filters_splice (&self->filters, position, 1, NULL, 0);
|
||||
gtk_filters_splice (&self->filters, position, 1, FALSE, NULL, 0);
|
||||
|
||||
gtk_filter_changed (GTK_FILTER (self),
|
||||
GTK_MULTI_FILTER_GET_CLASS (self)->removal_change);
|
||||
|
@ -432,7 +432,7 @@ gtk_multi_sorter_remove (GtkMultiSorter *self,
|
||||
|
||||
sorter = gtk_sorters_get (&self->sorters, position);
|
||||
g_signal_handlers_disconnect_by_func (sorter, gtk_multi_sorter_changed_cb, self);
|
||||
gtk_sorters_splice (&self->sorters, position, 1, NULL, 0);
|
||||
gtk_sorters_splice (&self->sorters, position, 1, FALSE, NULL, 0);
|
||||
|
||||
gtk_sorter_changed_with_keys (GTK_SORTER (self),
|
||||
GTK_SORTER_CHANGE_LESS_STRICT,
|
||||
|
@ -1386,7 +1386,7 @@ gtk_snapshot_pop_one (GtkSnapshot *snapshot)
|
||||
|
||||
/* Remove all the state's nodes from the list of nodes */
|
||||
g_assert (state->start_node_index + state->n_nodes == gtk_snapshot_nodes_get_size (&snapshot->nodes));
|
||||
gtk_snapshot_nodes_splice (&snapshot->nodes, state->start_node_index, state->n_nodes, NULL, 0);
|
||||
gtk_snapshot_nodes_splice (&snapshot->nodes, state->start_node_index, state->n_nodes, FALSE, NULL, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1400,7 +1400,7 @@ gtk_snapshot_pop_one (GtkSnapshot *snapshot)
|
||||
g_assert (previous_state->start_node_index + previous_state->n_nodes == gtk_snapshot_nodes_get_size (&snapshot->nodes));
|
||||
}
|
||||
|
||||
gtk_snapshot_states_splice (&snapshot->state_stack, state_index, 1, NULL, 0);
|
||||
gtk_snapshot_states_splice (&snapshot->state_stack, state_index, 1, FALSE, NULL, 0);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ gtk_string_list_splice (GtkStringList *self,
|
||||
else
|
||||
n_additions = 0;
|
||||
|
||||
objects_splice (&self->items, position, n_removals, NULL, n_additions);
|
||||
objects_splice (&self->items, position, n_removals, FALSE, NULL, n_additions);
|
||||
|
||||
for (i = 0; i < n_additions; i++)
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ gdk_array(test_splice) (void)
|
||||
for (j = 0; j < add; j++)
|
||||
sum += ++additions[j];
|
||||
|
||||
gdk_array(splice) (&v, pos, remove, additions, add);
|
||||
gdk_array(splice) (&v, pos, remove, FALSE, additions, add);
|
||||
{
|
||||
gsize total = 0;
|
||||
for (j = 0; j < gdk_array(get_size) (&v); j++)
|
||||
|
Loading…
Reference in New Issue
Block a user