From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oNPqGXdIHWC6SAAA0tVLHw (envelope-from ) for ; Fri, 05 Feb 2021 13:30:31 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id WHVtFXdIHWBucgAAbx9fmQ (envelope-from ) for ; Fri, 05 Feb 2021 13:30:31 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E15099404CE for ; Fri, 5 Feb 2021 13:30:30 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id EF0781FC0A; Fri, 5 Feb 2021 08:28:22 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 106AA1FCE4 for ; Fri, 5 Feb 2021 08:27:34 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 0A9366067F; Fri, 5 Feb 2021 08:27:34 -0500 (EST) Received: (nullmailer pid 3258373 invoked by uid 1000); Fri, 05 Feb 2021 13:27:02 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 01/39] lib: add _notmuch_string_map_set Date: Fri, 5 Feb 2021 09:26:16 -0400 Message-Id: <20210205132654.3258292-2-david@tethera.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205132654.3258292-1-david@tethera.net> References: <20210205132654.3258292-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: JKSRW5A3BPLMGXVIE7QHD6CNMKZG7V6J X-Message-ID-Hash: JKSRW5A3BPLMGXVIE7QHD6CNMKZG7V6J X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -0.93 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: E15099404CE X-Spam-Score: -0.93 X-Migadu-Scanner: scn0.migadu.com X-TUID: oWL+AoikIldM This will be used (and tested) by the configuration caching code to be added in the next commit. --- lib/notmuch-private.h | 5 +++++ lib/string-map.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) 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) { -- 2.30.0