[vala/staging] glib-2.0: Add GLib.[S]List.is_empty() convenience methods for non-null



commit 822c05ed78b875fabac8c84203c51b2427fa1c27
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Nov 25 13:29:51 2020 +0100

    glib-2.0: Add GLib.[S]List.is_empty() convenience methods for non-null

 tests/basic-types/glists.vala |  3 +++
 vapi/glib-2.0.vapi            | 10 ++++++++++
 2 files changed, 13 insertions(+)
---
diff --git a/tests/basic-types/glists.vala b/tests/basic-types/glists.vala
index 0d25e4481..56f03c3a4 100644
--- a/tests/basic-types/glists.vala
+++ b/tests/basic-types/glists.vala
@@ -1,5 +1,6 @@
 void test_glist () {
        var list = new GLib.List<string> ();
+       assert (list.is_empty ());
        list.prepend ("foo");
        list.prepend ("bar");
        assert (list.nth_data (1) == "foo");
@@ -14,6 +15,7 @@ void test_glist () {
 
 void test_gslist () {
        var list = new GLib.SList<string> ();
+       assert (list.is_empty ());
        list.prepend ("foo");
        list.prepend ("bar");
        assert (list.nth_data (1) == "foo");
@@ -28,6 +30,7 @@ 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.peek_nth (1) == "foo");
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<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;
        }


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