X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fstring-map.c;fp=lib%2Fstring-map.c;h=71eac6349a896ef49fe1cbfea3378a308951e1a4;hb=763445beaec906440fbdd497755718ef860b88e4;hp=a88404c734ff5a93ab98349bcc7913229bd19e47;hpb=8b7c09c66bbae35c52150a5ee81b94a82b2b3054;p=notmuch diff --git a/lib/string-map.c b/lib/string-map.c index a88404c7..71eac634 100644 --- a/lib/string-map.c +++ b/lib/string-map.c @@ -143,6 +143,24 @@ bsearch_first (notmuch_string_pair_t *array, size_t len, const char *key, bool e } +void +_notmuch_string_map_set (notmuch_string_map_t *map, + const char *key, + const char *val) +{ + notmuch_string_pair_t *pair; + + /* this means that calling string_map_set invalidates iterators */ + _notmuch_string_map_sort (map); + pair = bsearch_first (map->pairs, map->length, key, true); + if (! pair) + _notmuch_string_map_append (map, key, val); + else { + talloc_free (pair->value); + pair->value = talloc_strdup (map->pairs, val); + } +} + const char * _notmuch_string_map_get (notmuch_string_map_t *map, const char *key) {