[gtk/wip/otte/lottie: 8/86] gdkarray: Add a "stolen" boolean to splice()




commit 96e1b85c2cfec83961b2a667833155cef3a4b073
Author: Benjamin Otte <otte redhat com>
Date:   Wed Dec 23 20:04:29 2020 +0100

    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.

 gdk/gdkarrayimpl.c        | 11 +++++++----
 gtk/gtkactionmuxer.c      |  2 +-
 gtk/gtkcssselector.c      |  2 +-
 gtk/gtkmultifilter.c      |  2 +-
 gtk/gtkmultisorter.c      |  2 +-
 gtk/gtksnapshot.c         |  4 ++--
 gtk/gtkstringlist.c       |  2 +-
 testsuite/gdk/arrayimpl.c |  2 +-
 8 files changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/gdk/gdkarrayimpl.c b/gdk/gdkarrayimpl.c
index 003c67fd59..a18ab5e33d 100644
--- a/gdk/gdkarrayimpl.c
+++ b/gdk/gdkarrayimpl.c
@@ -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
diff --git a/gtk/gtkactionmuxer.c b/gtk/gtkactionmuxer.c
index fad926ceaf..fb3c4fb5a3 100644
--- a/gtk/gtkactionmuxer.c
+++ b/gtk/gtkactionmuxer.c
@@ -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 >
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index b8ef92a9ae..f04a6fe7c5 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -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
diff --git a/gtk/gtkmultifilter.c b/gtk/gtkmultifilter.c
index 8211295fb2..3550d90c58 100644
--- a/gtk/gtkmultifilter.c
+++ b/gtk/gtkmultifilter.c
@@ -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);
diff --git a/gtk/gtkmultisorter.c b/gtk/gtkmultisorter.c
index 5690d6d1d0..a733f5a275 100644
--- a/gtk/gtkmultisorter.c
+++ b/gtk/gtkmultisorter.c
@@ -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,
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index 7c5c744842..e01ce5ec68 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -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;
 }
diff --git a/gtk/gtkstringlist.c b/gtk/gtkstringlist.c
index 64e2e56155..c271ed91c1 100644
--- a/gtk/gtkstringlist.c
+++ b/gtk/gtkstringlist.c
@@ -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++)
     {
diff --git a/testsuite/gdk/arrayimpl.c b/testsuite/gdk/arrayimpl.c
index 286f64d678..77494fbf70 100644
--- a/testsuite/gdk/arrayimpl.c
+++ b/testsuite/gdk/arrayimpl.c
@@ -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++)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]