X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fstring-map.c;h=e3a81b4fe1457a030154fb3cb05cfc59cd3bb059;hb=0a32741fceb7778ced34064eacb7b5aac2c71638;hp=ad818207f5d4a91450336a99af2518ffcd2b8bc3;hpb=3a747e714c3e99a725619d09d832b9ac683733fe;p=notmuch diff --git a/lib/string-map.c b/lib/string-map.c index ad818207..e3a81b4f 100644 --- a/lib/string-map.c +++ b/lib/string-map.c @@ -106,7 +106,7 @@ _notmuch_string_map_sort (notmuch_string_map_t *map) map->sorted = true; } -static bool +static int string_cmp (const char *a, const char *b, bool exact) { if (exact) @@ -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) {