Add split functions for the linked lists
@ebassi
Submitted by Emmanuele Bassi Link to original bug (#440732)
Description
lately, I've been using a lot this code pattern to clamp a list:
if (g_list_length (list) > limit)
{
GList *l, *clamp;
clamp = g_list_nth (list, limit - 1);
l = clamp->next;
l->prev = NULL;
clamp->next = NULL;
g_list_foreach (l, (GFunc) my_free_func, NULL);
g_list_free (l);
}
it would be interesting to have the clamping code directly inside GLib:
GList *l = g_list_split (list, limit);
g_list_foreach (l, (GFunc) my_free_func, NULL);
g_list_free (l);
the attached patch implements g_list_split()
and g_slist_split()
.
Edited by Emmanuele Bassi