From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 89E661F66F for ; Tue, 3 Nov 2020 16:08:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727901AbgKCQIT (ORCPT ); Tue, 3 Nov 2020 11:08:19 -0500 Received: from cloud.peff.net ([104.130.231.41]:46188 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727812AbgKCQIT (ORCPT ); Tue, 3 Nov 2020 11:08:19 -0500 Received: (qmail 6439 invoked by uid 109); 3 Nov 2020 16:08:19 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Tue, 03 Nov 2020 16:08:19 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 1873 invoked by uid 111); 3 Nov 2020 16:08:18 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Tue, 03 Nov 2020 11:08:18 -0500 Authentication-Results: peff.net; auth=none Date: Tue, 3 Nov 2020 11:08:18 -0500 From: Jeff King To: Elijah Newren Cc: Elijah Newren via GitGitGadget , Git Mailing List Subject: Re: [PATCH v2 03/10] hashmap: allow re-use after hashmap_free() Message-ID: <20201103160818.GB444466@coredump.intra.peff.net> References: <20201030133518.GC3277724@coredump.intra.peff.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Fri, Oct 30, 2020 at 08:37:42AM -0700, Elijah Newren wrote: > > This part I disagree with. If we did: > > > > #define HASHMAP_INIT(fn, data) = { .cmpfn = cmpfn, cmpfn_data = data } > > > > then many callers could avoid handling the lazy-init themselves. E.g.: > > Ah, gotcha. That makes sense to me. Given that 43 out of 47 callers > of hashmap_init use cmpfn_data = NULL, should I shorten it to just one > parameter for the macro, and let the four special cases keep calling > hashmap_init() to specify a non-NULL cmpfn_data? I'd be fine with it either way. I actually wrote it without the data parameter at first, then changed my mine and added it in. ;) You could also do: #define HASHMAP_INIT_DATA(fn, data) { .cmpfn = cmpfn, cmpfn_data = data } #define HASHMAP_INIT(fn) HASHMAP_INIT_DATA(fn, NULL) if you want to keep most callers simple. -Peff