From: David Bremner Date: Sun, 20 Dec 2020 21:10:53 +0000 (-0400) Subject: lib: add _notmuch_string_map_set X-Git-Tag: 0.32_rc0~117 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=763445beaec906440fbdd497755718ef860b88e4 lib: add _notmuch_string_map_set This will be used (and tested) by the configuration caching code to be added in the next commit. --- diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 57ec7f72..51016b0b 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -638,6 +638,11 @@ _notmuch_string_map_append (notmuch_string_map_t *map, const char *key, const char *value); +void +_notmuch_string_map_set (notmuch_string_map_t *map, + const char *key, + const char *value); + const char * _notmuch_string_map_get (notmuch_string_map_t *map, const char *key); 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) {