mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
lib: add _notmuch_string_map_set
This will be used (and tested) by the configuration caching code to be added in the next commit.
This commit is contained in:
parent
8b7c09c66b
commit
763445beae
2 changed files with 23 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue