diff --git a/glib/garraylist.c b/glib/garraylist.c index 51086ff4a..a08462289 100644 --- a/glib/garraylist.c +++ b/glib/garraylist.c @@ -165,7 +165,7 @@ g_array_list_peek (GArrayList *self) gpointer g_array_list_index (GArrayList *self, - guint index) + gsize index) { GArrayListAny *any = (GArrayListAny *)self; GArrayListEmbed *embed = (GArrayListEmbed *)self; @@ -426,3 +426,24 @@ g_array_list_destroy (GArrayList *self) if (any->on_heap) g_slice_free (GArrayListAny, any); } + +const GList * +g_array_list_last_link (GArrayList *self) +{ + GArrayListAny *any = (GArrayListAny *)self; + GArrayListEmbed *embed = (GArrayListEmbed *)self; + GArrayListAlloc *alloc = (GArrayListAlloc *)self; + GList *items; + + g_return_val_if_fail (self != NULL, NULL); + + if (self->len == 0) + return NULL; + + if (any->mode == MODE_EMBED) + items = embed->items; + else + items = alloc->items; + + return &items [self->len - 1]; +} diff --git a/glib/garraylist.h b/glib/garraylist.h index caf45c329..4483855d7 100644 --- a/glib/garraylist.h +++ b/glib/garraylist.h @@ -71,6 +71,9 @@ void g_array_list_remove_index (GArrayList *list, GLIB_AVAILABLE_IN_2_46 void g_array_list_destroy (GArrayList *list); +GLIB_AVAILABLE_IN_2_46 +const GList *g_array_list_last_link (GArrayList *list); + #define g_array_list_first(list) (((list)->len == 0) ? NULL : g_array_list_index((list),0)) #define g_array_list_last(list) (((list)->len == 0) ? NULL : g_array_list_index((list),(list)->len-1)) diff --git a/glib/tests/arraylist.c b/glib/tests/arraylist.c index 79ab3c51e..a716dc6a6 100644 --- a/glib/tests/arraylist.c +++ b/glib/tests/arraylist.c @@ -50,6 +50,9 @@ test_basic (GArrayList *al) g_assert_cmpint (GPOINTER_TO_SIZE (g_array_list_first(al)), ==, 1); g_assert_cmpint (GPOINTER_TO_SIZE (g_array_list_last(al)), ==, 1000); + iter = g_array_list_last_link (al); + g_assert_cmpint (GPOINTER_TO_SIZE (iter->data), ==, 1000); + list = g_array_list_peek (al); for (iter = list; iter; iter = iter->next)