[glib/wip/chergert/garraylist] arraylist: add g_array_list_first()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/chergert/garraylist] arraylist: add g_array_list_first()
- Date: Sun, 13 Sep 2015 10:22:20 +0000 (UTC)
commit 2f282b9577e83636279b2bb7b6194fdb2ad3af79
Author: Christian Hergert <christian hergert me>
Date: Sun Sep 13 03:21:30 2015 -0700
arraylist: add g_array_list_first()
glib/garraylist.h | 1 +
glib/tests/arraylist.c | 3 +++
2 files changed, 4 insertions(+), 0 deletions(-)
---
diff --git a/glib/garraylist.h b/glib/garraylist.h
index 43351bf..caf45c3 100644
--- a/glib/garraylist.h
+++ b/glib/garraylist.h
@@ -71,6 +71,7 @@ void g_array_list_remove_index (GArrayList *list,
GLIB_AVAILABLE_IN_2_46
void g_array_list_destroy (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))
G_END_DECLS
diff --git a/glib/tests/arraylist.c b/glib/tests/arraylist.c
index 81712c8..79ab3c5 100644
--- a/glib/tests/arraylist.c
+++ b/glib/tests/arraylist.c
@@ -39,12 +39,15 @@ test_basic (GArrayList *al)
g_assert (al != NULL);
g_assert_cmpint (al->len, ==, 0);
+ g_assert_cmpint (GPOINTER_TO_SIZE (g_array_list_first(al)), ==, 0);
+
for (i = 1; i <= 1000; i++)
{
g_array_list_add (al, GSIZE_TO_POINTER (i));
g_assert_cmpint (al->len, ==, i);
}
+ g_assert_cmpint (GPOINTER_TO_SIZE (g_array_list_first(al)), ==, 1);
g_assert_cmpint (GPOINTER_TO_SIZE (g_array_list_last(al)), ==, 1000);
list = g_array_list_peek (al);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]