> Hi Jaakko,
>
> On ke, 2015-07-15 at 11:35 +0300, Jaakko Hannikainen wrote:
>> This helper function takes in a heap-allocated buffer of heap-allocated
>> strings. If no strings should be removed, return the buffer. Else, free
>> all empty strings, place nonempty strings to a new container and return
>> it, freeing the old container.
>> ---
>>  src/service.c | 32 ++++++++++++++++++++++++++++++++
>>  1 file changed, 32 insertions(+)
>>
>> diff --git a/src/service.c b/src/service.c
>> index 2d8245e..1723586 100644
>> --- a/src/service.c
>> +++ b/src/service.c
>> @@ -2926,6 +2926,38 @@ static DBusMessage *get_properties(DBusConnection 
>> *conn,
>>      return reply;
>>  }
>>  
>> +static char **remove_empty_strings(char **strv)
>> +{
>> +    int amount, length, index;
>> +    char **iter, **out;
>> +
>> +    amount = 0;
>> +    length = g_strv_length(strv);
> We could remove the call to g_strv_length() and calculate the max length
> in the while loop below.
>
>> +    iter = strv;
>> +
>> +    while (*iter)
>> +            if (strlen(*iter++))
>> +                    amount++;

And it's unnecessary to calculate the length of each string. Twice.

It would suffice to just check the first byte.

Regards,
-Slava
_______________________________________________
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman

Reply via email to