g_list_copy_deep and g_slist_copy_deep in GLib

If you have in your code things like that:

copy = g_slist_copy (list);
g_slist_foreach (copy, g_object_ref, NULL);

In GLib 2.34 (to be released soon) you can do:

copy = g_slist_copy_deep (list, g_object_ref, NULL);

Thus eliminating another loop in the list (one loop is done when copying the list).

In other words, there’s now a function to do a deep (full) copy of a GList and GSList. It accepts, besides the list to be cloned, a function as a second argument, and a user data as the third argument. That function will be called for each element in the list.

To free the new list, use g_list_free_full().


#1 Matthew Barnes on 06.21.12 at 07:12 PM

Please don’t forget GQueue.

#2 Robert Ancell on 06.21.12 at 10:22 PM

That’s awsome!

#3 Benjamim Janeiro on 06.27.12 at 09:43 AM

On the Ubuntu Vinagre remote control program please consider to add a space (a line) to add comments.
Example : Comment: Computador do João
Awsome job !!