[glib/wip/chergert/garraylist] arraylist: add g_array_list_last()



commit ca7bd22034dbcfd9d6454904b6a42f4b494a1b29
Author: Christian Hergert <christian hergert me>
Date:   Sun Sep 13 03:20:02 2015 -0700

    arraylist: add g_array_list_last()

 glib/garraylist.h      |    2 ++
 glib/tests/arraylist.c |    2 ++
 2 files changed, 4 insertions(+), 0 deletions(-)
---
diff --git a/glib/garraylist.h b/glib/garraylist.h
index b885908..43351bf 100644
--- a/glib/garraylist.h
+++ b/glib/garraylist.h
@@ -71,6 +71,8 @@ void         g_array_list_remove_index (GArrayList     *list,
 GLIB_AVAILABLE_IN_2_46
 void         g_array_list_destroy      (GArrayList     *list);
 
+#define g_array_list_last(list) (((list)->len == 0) ? NULL : g_array_list_index((list),(list)->len-1))
+
 G_END_DECLS
 
 #endif /* __G_ARRAY_LIST_H__ */
diff --git a/glib/tests/arraylist.c b/glib/tests/arraylist.c
index 8d92acb..81712c8 100644
--- a/glib/tests/arraylist.c
+++ b/glib/tests/arraylist.c
@@ -45,6 +45,8 @@ test_basic (GArrayList *al)
       g_assert_cmpint (al->len, ==, i);
     }
 
+  g_assert_cmpint (GPOINTER_TO_SIZE (g_array_list_last(al)), ==, 1000);
+
   list = g_array_list_peek (al);
 
   for (iter = list; iter; iter = iter->next)


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