Re: [Vala] How to check if GLib.List is empty?
- From: Luca Bruno <lethalman88 gmail com>
- To: vala-list gnome org
- Subject: Re: [Vala] How to check if GLib.List is empty?
- Date: Tue, 02 Dec 2014 16:22:30 +0100
On 02/12/2014 16:03, Виталий Кирсанов wrote:
Hello list.
Probably there is a well-known answer to this but I failed to find it.
Native C glib states that a null pointer GList is a valid list and it can
be used as an argument to various list operations such as g_list_append().
And to check whether the list is empty you need just to compare the head of
the list with NULL;
But it's not that straightforward with vala. If I write:
var list = List<string>();
then vala generates something like:
GList * list = NULL;
And after that I can call some of methods of list (e.g.
list.append("hello");) but call to list.data would lead to a crash. That's
a bit strange but ok, I understand that functions able to operate null data
values like GList are not very well mapped to vala where this reference may
not be null.
The main question is when I have created list variable in vala, made some
insertions and deletions how do I check whether it is empty or not?
Probable answer would be I can call list.length(); method but it will not
be efficient if, say, I call it on every iteration of a loop and the list
is not empty.
Is there a more simple and efficient way?
== null
:)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]