From: Jani Nikula Date: Sun, 30 Aug 2015 07:45:46 +0000 (+0300) Subject: Re: [RFC PATCH 4/5] cli: change the data structure for notmuch address deduplication X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c6c48365cc0e2a2e1959c417c435fcac4379e046;p=notmuch-archives.git Re: [RFC PATCH 4/5] cli: change the data structure for notmuch address deduplication --- diff --git a/96/14d19e3c933b20d78ba6e85c1b7edd55084e14 b/96/14d19e3c933b20d78ba6e85c1b7edd55084e14 new file mode 100644 index 000000000..383d8974f --- /dev/null +++ b/96/14d19e3c933b20d78ba6e85c1b7edd55084e14 @@ -0,0 +1,189 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id E94CC6DE1422 + for ; Sun, 30 Aug 2015 00:45:51 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.033 +X-Spam-Level: +X-Spam-Status: No, score=-0.033 tagged_above=-999 required=5 + tests=[AWL=-0.057, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, + RCVD_IN_MSPIKE_WL=-0.01, URIBL_SBL=0.644, URIBL_SBL_A=0.1] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id byTyleT2gh1d for ; + Sun, 30 Aug 2015 00:45:50 -0700 (PDT) +Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com + [209.85.212.175]) + by arlo.cworth.org (Postfix) with ESMTPS id 87EF26DE00CB + for ; Sun, 30 Aug 2015 00:45:49 -0700 (PDT) +Received: by wicpl12 with SMTP id pl12so3317022wic.0 + for ; Sun, 30 Aug 2015 00:45:48 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:subject:in-reply-to:references + :user-agent:date:message-id:mime-version:content-type; + bh=qSlXICt/pbAC9rCNI1L5nMjtwb7TGNF+NmQB6hAjvhA=; + b=EPo3kTyUr5wWepVSU8zDSmvWwBB+65wwEWURmMi22B9pD2JgsA14MasEaZnr/G2IxM + BgUMQGSGy25ywLhwYnlgJl7aT6nwajw5FqG0A4dXJswFQMFOgEWXzwc74hs+pzZKNjfO + VjoQ3aPDgsSaV5ywDuWPPYLqvGG26vLzcdOmnNd0yT/3YmgTh5LWadBnDQL/1ofHbWYO + heIjFKiGcLMH9rW9MWwbazrdmPWeDjSqcHP+whXGrnV3KYpONVBPw4PuTPNhXy7BH75g + 4Wm63UCDCaklVWf5jm0wFy4KAA1YalDcPBdPHG9gkrKpaM5qrGIiB8rvr7C3ueS/7Pnj + sI2g== +X-Gm-Message-State: + ALoCoQmZpX8oV9HKzmP18JAPpmYSiLLlBj91yFNkkidXzvHdkxP9n7HMxF0Lk+v+65snEE1uFd9F +X-Received: by 10.180.82.7 with SMTP id e7mr13160658wiy.19.1440920747872; + Sun, 30 Aug 2015 00:45:47 -0700 (PDT) +Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi. + [188.238.79.131]) + by smtp.gmail.com with ESMTPSA id du6sm11961009wib.24.2015.08.30.00.45.46 + (version=TLSv1/SSLv3 cipher=OTHER); + Sun, 30 Aug 2015 00:45:47 -0700 (PDT) +From: Jani Nikula +To: David Bremner , notmuch@notmuchmail.org +Subject: Re: [RFC PATCH 4/5] cli: change the data structure for notmuch + address deduplication +In-Reply-To: <87a8t9tuka.fsf@maritornes.cs.unb.ca> +References: + + <87a8t9tuka.fsf@maritornes.cs.unb.ca> +User-Agent: Notmuch/0.20.2+66~gb33abd9 (http://notmuchmail.org) Emacs/24.4.1 + (x86_64-pc-linux-gnu) +Date: Sun, 30 Aug 2015 10:45:46 +0300 +Message-ID: <87h9nh1aol.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 30 Aug 2015 07:45:52 -0000 + +On Sun, 30 Aug 2015, David Bremner wrote: +> Jani Nikula writes: +> +>> +>> +static int +>> +strcase_equal (const void *a, const void *b) +>> +{ +>> + return strcasecmp (a, b) == 0; +>> +} +>> + +>> +static unsigned int +>> +strcase_hash (const void *ptr) +>> +{ +>> + const char *s = ptr; +>> + +>> + /* This is the djb2 hash. */ +>> + unsigned int hash = 5381; +>> + while (s && *s) { +>> + hash = ((hash << 5) + hash) + tolower (*s); +>> + s++; +>> + } +>> + +>> + return hash; +>> +} +>> + +> +> as discussed, these functions probably need to be factored out into +> libutil. + +Ack. + +> +>> + l = g_list_find_custom (list, mailbox, mailbox_compare); +>> + if (l) { +>> + talloc_free (mailbox); +>> + mailbox = l->data; +>> + mailbox->count++; +>> + return TRUE; +>> + } +> +> I found this use of mailbox as a temporary variable confusing; despite +> the obvious return I thought it might have something to do with the +> g_list_append below. Maybe just make a block scope temporary variable? + +This is how the function would turn out with that. Better, I guess? I +also tried to think of ways to combine the two g_list_append paths here, +but in the end doing it like this has most clarity I think. + +static notmuch_bool_t +is_duplicate (const search_context_t *ctx, const char *name, const char *addr) +{ + char *key; + GList *list, *l; + mailbox_t *mailbox; + + list = g_hash_table_lookup (ctx->addresses, addr); + if (list) { + mailbox_t find = { + .name = name, + .addr = addr, + }; + + l = g_list_find_custom (list, &find, mailbox_compare); + if (l) { + mailbox = l->data; + mailbox->count++; + return TRUE; + } + + mailbox = new_mailbox (ctx->format, name, addr); + if (! mailbox) + return FALSE; + + g_list_append (list, mailbox); + return FALSE; + } + + key = talloc_strdup (ctx->format, addr); + if (! key) + return FALSE; + + mailbox = new_mailbox (ctx->format, name, addr); + if (! mailbox) + return FALSE; + + list = g_list_append (NULL, mailbox); + if (! list) + return FALSE; + + g_hash_table_insert (ctx->addresses, key, list); + + return FALSE; +} + +>> + +>> + g_list_append (list, mailbox); +>> + return FALSE; +>> } +>> +>> - mailbox = new_mailbox (ctx->format, name, addr); +>> - if (! mailbox) +>> + key = talloc_strdup (ctx->format, addr); +>> + if (! key) +>> return FALSE; +> +> I guess this doesn't make the error handling worse; both old and new +> code silently ignore OOM if I understand correctly. Do you happen to +> understand the original choice of using ctx->format rather than that +> ctx->notmuch for a talloc parent? it doesn't seem to get deallocated any +> earlier. + +I don't know or understand that part of the history. It doesn't really +matter though because the deallocation is explicitly done on all keys +and values via g_hash_table_unref. + +BR, +Jani.