--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 82B9E6DE0B7C\r
+ for <notmuch@notmuchmail.org>; Thu, 24 Sep 2015 11:34:54 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.144\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.144 tagged_above=-999 required=5\r
+ tests=[AWL=-0.168, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
+ RCVD_IN_MSPIKE_WL=-0.01, URIBL_SBL=0.644, URIBL_SBL_A=0.1]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id NBZ1QLCyxlg9 for <notmuch@notmuchmail.org>;\r
+ Thu, 24 Sep 2015 11:34:52 -0700 (PDT)\r
+Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com\r
+ [209.85.212.174])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 9DCC56DE0B64\r
+ for <notmuch@notmuchmail.org>; Thu, 24 Sep 2015 11:34:51 -0700 (PDT)\r
+Received: by wiclk2 with SMTP id lk2so125067381wic.1\r
+ for <notmuch@notmuchmail.org>; Thu, 24 Sep 2015 11:34:49 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=AbjQtlAGaBJ7UpHzwYDcPbI+XjKqIo8M9MaZdTgxqDQ=;\r
+ b=luQgGMFqrXZc8Zyzn21LO8p7nJmUB4V+eIGNsiDAcwJmzTOoqiv2UK0gdXeRB6AfkR\r
+ PNDwj9k7TywwCR4NGv2nREhNlxtYqk7X4mlZ5KJH5Gd32uvTYZt/gF64lN0YJWxsHvv2\r
+ nsaF9tWk2FVE4UHVdrn2jZ+z2UyUQiepti6XOI0jWPfpiNdX+/K1bRJaCTFreH1zajor\r
+ rOqqnY8eFnwTCenWB4DSflRJpWE2H9OwlmO/txqE4Uy4hzly3rCepjyyjDwd5T0RtbQv\r
+ b/DVazpfyzjQyfxj8b+ZKCJHzsh9VFRNK0t+yHAJLzRSh9F4mWOmuogUZ6FzUhQWNILF\r
+ yRCQ==\r
+X-Gm-Message-State:\r
+ ALoCoQkmzFWDH7PeSVSxjElnnYSyDjjz6qpObdf8KjHfZ9DXRGmL6LVDpYJFDztbJHgemVfvuX/Q\r
+X-Received: by 10.194.116.67 with SMTP id ju3mr1165206wjb.143.1443119689474;\r
+ Thu, 24 Sep 2015 11:34:49 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee63-221.dhcp.inet.fi.\r
+ [188.238.99.221])\r
+ by smtp.gmail.com with ESMTPSA id jj8sm169536wid.2.2015.09.24.11.34.48\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Thu, 24 Sep 2015 11:34:48 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 6/9] cli: change the data structure for notmuch address\r
+ deduplication\r
+In-Reply-To: <87fv242e2a.fsf@zancas.localnet>\r
+References: <cover.1441308761.git.jani@nikula.org>\r
+ <d8bb01aff648f9b73ec5f09f0e86e42dac2a21a6.1441308761.git.jani@nikula.org>\r
+ <87fv242e2a.fsf@zancas.localnet>\r
+User-Agent: Notmuch/0.20.2+66~gb33abd9 (http://notmuchmail.org) Emacs/24.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Thu, 24 Sep 2015 21:34:30 +0300\r
+Message-ID: <87612zwts9.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 24 Sep 2015 18:34:54 -0000\r
+\r
+On Thu, 24 Sep 2015, David Bremner <david@tethera.net> wrote:\r
+> Jani Nikula <jani@nikula.org> writes:\r
+>\r
+>\r
+>> + else\r
+>> + v = !!m1->name - !!m2->name;\r
+>\r
+> Is this really idiomatic? It seems a little difficult to follow to me.\r
+\r
+Probably depends on whether you're accustomed to using !! for\r
+"normalizing" zero and non-zero to 0 and 1, respectively.\r
+\r
+The alternative seemed a bit too verbose for my liking:\r
+\r
+ if (m1->name && m2->name)\r
+ v = strcmp (m1->name, m2->name);\r
+ else if (!m1->name && !m2->name)\r
+ v = 0;\r
+ else if (m1->name)\r
+ v = 1;\r
+ else\r
+ v = -1;\r
+\r
+I can live with that if you think the verbosity is in order here. (Or am\r
+I missing an obvious better alternative?)\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+>\r
+>> /* Returns TRUE iff name and addr is duplicate. If not, stores the\r
+>> * name/addr pair in order to detect subsequent duplicates. */\r
+>> static notmuch_bool_t\r
+>> is_duplicate (const search_context_t *ctx, const char *name, const char *addr)\r
+>> {\r
+>> char *key;\r
+>> + GList *list, *l;\r
+>> mailbox_t *mailbox;\r
+>> \r
+>> - key = talloc_asprintf (ctx->format, "%s <%s>", name, addr);\r
+>> - if (! key)\r
+>> - return FALSE;\r
+>> + list = g_hash_table_lookup (ctx->addresses, addr);\r
+>> + if (list) {\r
+>> + mailbox_t find = {\r
+>> + .name = name,\r
+>> + .addr = addr,\r
+>> + };\r
+>> +\r
+>> + l = g_list_find_custom (list, &find, mailbox_compare);\r
+>> + if (l) {\r
+>> + mailbox = l->data;\r
+>> + mailbox->count++;\r
+>> + return TRUE;\r
+>> + }\r
+>> \r
+>> - mailbox = g_hash_table_lookup (ctx->addresses, key);\r
+>> - if (mailbox) {\r
+>> - mailbox->count++;\r
+>> - talloc_free (key);\r
+>> - return TRUE;\r
+>> + mailbox = new_mailbox (ctx->format, name, addr);\r
+>> + if (! mailbox)\r
+>> + return FALSE;\r
+>> +\r
+>> + /*\r
+>> + * XXX: It would be more efficient to prepend to the list, but\r
+>> + * then we'd have to store the changed list head back to the\r
+>> + * hash table. This check is here just to avoid the compiler\r
+>> + * warning for unused result.\r
+>> + */\r
+>> + if (list != g_list_append (list, mailbox))\r
+>> + INTERNAL_ERROR ("appending to list changed list head\n");\r
+>> +\r
+>> + return FALSE;\r
+>> }\r
+>> \r
+>> + key = talloc_strdup (ctx->format, addr);\r
+>> + if (! key)\r
+>> + return FALSE;\r
+>> +\r
+>> mailbox = new_mailbox (ctx->format, name, addr);\r
+>> if (! mailbox)\r
+>> return FALSE;\r
+>> \r
+>> - g_hash_table_insert (ctx->addresses, key, mailbox);\r
+>> + list = g_list_append (NULL, mailbox);\r
+>> + if (! list)\r
+>> + return FALSE;\r
+>> +\r
+>> + g_hash_table_insert (ctx->addresses, key, list);\r
+>> \r
+>> return FALSE;\r
+>> }\r
+>> @@ -401,12 +445,21 @@ _talloc_free_for_g_hash (void *ptr)\r
+>> }\r
+>> \r
+>> static void\r
+>> -print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)\r
+>> +_list_free_for_g_hash (void *ptr)\r
+>> +{\r
+>> + g_list_free_full (ptr, _talloc_free_for_g_hash);\r
+>> +}\r
+>> +\r
+>> +static void\r
+>> +print_list_value (void *mailbox, void *context)\r
+>> {\r
+>> - const mailbox_t *mailbox = value;\r
+>> - search_context_t *ctx = user_data;\r
+>> + print_mailbox (context, mailbox);\r
+>> +}\r
+>> \r
+>> - print_mailbox (ctx, mailbox);\r
+>> +static void\r
+>> +print_hash_value (unused (void *key), void *list, void *context)\r
+>> +{\r
+>> + g_list_foreach (list, print_list_value, context);\r
+>> }\r
+>> \r
+>> static int\r
+>> @@ -792,8 +845,9 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])\r
+>> argc - opt_index, argv + opt_index))\r
+>> return EXIT_FAILURE;\r
+>> \r
+>> - ctx->addresses = g_hash_table_new_full (g_str_hash, g_str_equal,\r
+>> - _talloc_free_for_g_hash, _talloc_free_for_g_hash);\r
+>> + ctx->addresses = g_hash_table_new_full (strcase_hash, strcase_equal,\r
+>> + _talloc_free_for_g_hash,\r
+>> + _list_free_for_g_hash);\r
+>> \r
+>> ret = do_search_messages (ctx);\r
+>> \r
+>> -- \r
+>> 2.1.4\r
+>>\r
+>> _______________________________________________\r
+>> notmuch mailing list\r
+>> notmuch@notmuchmail.org\r
+>> http://notmuchmail.org/mailman/listinfo/notmuch\r