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




commit 3f2a66e9853e36889049aacda354aaf85c956821
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 |  6 ++++++
 vapi/glib-2.0.vapi            | 10 ++++++++++
 2 files changed, 16 insertions(+)
---
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<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;
 
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]