]> git.notmuchmail.org Git - notmuch/commitdiff
lib: add _notmuch_string_map_set
authorDavid Bremner <david@tethera.net>
Sun, 20 Dec 2020 21:10:53 +0000 (17:10 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 6 Feb 2021 22:54:23 +0000 (18:54 -0400)
This will be used (and tested) by the configuration caching code to be
added in the next commit.

lib/notmuch-private.h
lib/string-map.c

index 57ec7f72eae530b8aa82efb6598065382947064f..51016b0b430017397cc5cc86ab518994fe432550 100644 (file)
@@ -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);
 
index a88404c734ff5a93ab98349bcc7913229bd19e47..71eac6349a896ef49fe1cbfea3378a308951e1a4 100644 (file)
@@ -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)
 {