Lennart Poettering <lenn...@poettering.net> writes:
> On Fri, 14.11.14 12:42, Jan Synacek (jsyna...@redhat.com) wrote:
>> +        if (look_for == LAYOUTS) {
>> +                Set *s;
>> +                char *k;
>> +                Iterator i;
>> +                /* XXX: Is there a better way to sort Hashmap keys? */
>> +                _cleanup_strv_free_ char **tmp = NULL;
>> +
>> +                HASHMAP_FOREACH_KEY(s, k, keymap->x11_layouts, i)
>> +                        if (strv_extend(&tmp, k) < 0)
>> +                                (void) log_oom();
>
> There's hashmap_get_strv() for cases like this.

I need keys, not values. I didn't find any hashmap_get_strv() equivalent
for keys.

>
> Also, please neer invoke strv_extend() when appending to unbounded
> arrays. It's slow! 

What is a preffered way to extend a strv? In this case, I know the final
size, so it the array could manually be copied. I don't think that
that's very nice, though.

>> +void xkb_keymap_free_components(X11Keymap *keymap) {
>> +        if (keymap->x11_layouts) {
>> +                Set *s;
>> +                char *k;
>> +                Iterator i;
>> +
>> +                HASHMAP_FOREACH_KEY(s, k, keymap->x11_layouts, i) {
>> +                        free(k);
>> +                        set_free_free(s);
>> +                }
>
> Humm, when clearing up hashmaps please just write a loop that steals
> the first entry, free it and then repeat. Iterating through a hashmap
> while deleting its entries is unnecessary...

I need to free its entries *and* keys. I didn't find any function that I
could use for that, apart from hashmap_free_free(), which crashes in my case.

> Lennart
>
> -- 
> Lennart Poettering, Red Hat

Cheers,
-- 
Jan Synacek
Software Engineer, Red Hat

Attachment: signature.asc
Description: PGP signature

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to