From: Rico Tzschichholz Date: Wed, 25 Nov 2020 12:29:51 +0000 (+0100) Subject: glib-2.0: Add GLib.[S]List.is_empty() convenience methods for non-null X-Git-Tag: 0.51.1~146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f2a66e9853e36889049aacda354aaf85c956821;p=thirdparty%2Fvala.git glib-2.0: Add GLib.[S]List.is_empty() convenience methods for non-null --- diff --git a/tests/basic-types/glists.vala b/tests/basic-types/glists.vala index 0d25e4481..869b9fda0 100644 --- a/tests/basic-types/glists.vala +++ b/tests/basic-types/glists.vala @@ -1,7 +1,9 @@ void test_glist () { var list = new GLib.List (); + assert (list.is_empty ()); list.prepend ("foo"); list.prepend ("bar"); + assert (!list.is_empty ()); assert (list.nth_data (1) == "foo"); list = null; @@ -14,8 +16,10 @@ void test_glist () { void test_gslist () { var list = new GLib.SList (); + assert (list.is_empty ()); list.prepend ("foo"); list.prepend ("bar"); + assert (!list.is_empty ()); assert (list.nth_data (1) == "foo"); list = null; @@ -28,8 +32,10 @@ void test_gslist () { void test_gqueue () { var queue = new GLib.Queue (); + assert (queue.is_empty ()); queue.push_head ("foo"); queue.push_head ("bar"); + assert (!queue.is_empty ()); assert (queue.peek_nth (1) == "foo"); queue = null; diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 3ed2b2a4f..c612cc36e 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -4922,6 +4922,11 @@ namespace GLib { public int position (List llink); public int index (G data); + [CCode (cname = "vala_g_list_is_empty")] + public inline bool is_empty () { + return (List?) this == null; + } + public G data; public List next; public unowned List prev; @@ -4982,6 +4987,11 @@ namespace GLib { public int position (SList llink); public int index (G data); + [CCode (cname = "vala_g_slist_is_empty")] + public inline bool is_empty () { + return (SList?) this == null; + } + public G data; public SList next; }