Re: [Vala] How to check if string is empty

2017-01-17 Thread Ulink
Am 2017-01-17 um 12:09 schrieb rastersoft: > That's true for the first one, but the second is as fast as str[0] == 0, > because as soon as one byte doesn't fit, the function ends. You are right, because str=="" indeed calls g_strcmp0(), but str[0]=='\0' calls string_get() which seems not faster t

Re: [Vala] How to check if string is empty

2017-01-17 Thread rastersoft
Hi: El 17/01/17 a las 10:24, Ulink escribió: > But I think str.length==0 and str=="" are no high performance solutions, > especially for big/long strings. That's true for the first one, but the second is as fast as str[0] == 0, because as soon as one byte doesn't fit, the function ends. -- Nos l

Re: [Vala] How to check if string is empty

2017-01-17 Thread Ulink
As Guillaume wrote, you have to use string? str and check string==null FIRST. But I think str.length==0 and str=="" are no high performance solutions, especially for big/long strings. Maybe this is better? bool is_null_or_empty (string? str) { return str == null || str[0] == '\0'; }

Re: [Vala] How to check if string is empty

2017-01-17 Thread Dmitry Golovin
My mistake. Thanks for correcting me. 17.01.2017, 10:55, "Jens Georg" : >>  In Vala you can simply just check for str != "", this is enough. > > No, if str is nullable it's semantically different, because str != "" > will be generated as > > if (g_strcmp0 (_tmp1_, "") != 0) { >    .. > } > > This

Re: [Vala] How to check if string is empty

2017-01-17 Thread Jens Georg
In Vala you can simply just check for str != "", this is enough. No, if str is nullable it's semantically different, because str != "" will be generated as if (g_strcmp0 (_tmp1_, "") != 0) { .. } This will be TRUE for _tmp1_ being NULL because NULL isn't "" ( and g_strcmp0 will return -1