]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: Add GLib.[S]List.is_empty() convenience methods for non-null
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 25 Nov 2020 12:29:51 +0000 (13:29 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 25 Nov 2020 12:57:47 +0000 (13:57 +0100)
tests/basic-types/glists.vala
vapi/glib-2.0.vapi

index 0d25e448184aaa3d139d86f8e5d9d95f3aa12cf7..869b9fda02158379aac9890fb15355cfea70bde0 100644 (file)
@@ -1,7 +1,9 @@
 void test_glist () {
        var list = new GLib.List<string> ();
+       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<string> ();
+       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<string> ();
+       assert (queue.is_empty ());
        queue.push_head ("foo");
        queue.push_head ("bar");
+       assert (!queue.is_empty ());
        assert (queue.peek_nth (1) == "foo");
        queue = null;
 
index 3ed2b2a4f1420a552fb91778a4a34822ad56bf35..c612cc36ed34b43be715d75e31a447245263155b 100644 (file)
@@ -4922,6 +4922,11 @@ namespace GLib {
                public int position (List<G> 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<G> next;
                public unowned List<G> prev;
@@ -4982,6 +4987,11 @@ namespace GLib {
                public int position (SList<G> 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<G> next;
        }