aboutsummaryrefslogtreecommitdiff
path: root/lib/string-map.c
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2020-12-20 17:10:53 -0400
committerDavid Bremner <david@tethera.net>2021-02-06 18:54:23 -0400
commit763445beaec906440fbdd497755718ef860b88e4 (patch)
tree1ad6c547f11cf9a4fb2be33a0199f31457bf5a05 /lib/string-map.c
parent8b7c09c66bbae35c52150a5ee81b94a82b2b3054 (diff)
lib: add _notmuch_string_map_set
This will be used (and tested) by the configuration caching code to be added in the next commit.
Diffstat (limited to 'lib/string-map.c')
-rw-r--r--lib/string-map.c18
1 files changed, 18 insertions, 0 deletions
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)
{