From patchwork Thu Jun 25 19:48:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11626039 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A96AF912 for ; Thu, 25 Jun 2020 19:48:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D1EE207D8 for ; Thu, 25 Jun 2020 19:48:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406877AbgFYTs1 (ORCPT ); Thu, 25 Jun 2020 15:48:27 -0400 Received: from cloud.peff.net ([104.130.231.41]:43308 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406866AbgFYTs1 (ORCPT ); Thu, 25 Jun 2020 15:48:27 -0400 Received: (qmail 31409 invoked by uid 109); 25 Jun 2020 19:48:27 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Thu, 25 Jun 2020 19:48:27 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 19646 invoked by uid 111); 25 Jun 2020 19:48:27 -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; Thu, 25 Jun 2020 15:48:27 -0400 Authentication-Results: peff.net; auth=none Date: Thu, 25 Jun 2020 15:48:25 -0400 From: Jeff King To: git@vger.kernel.org Cc: Eric Sunshine , Junio C Hamano , Johannes Schindelin , SZEDER =?utf-8?b?R8OhYm9y?= Subject: [PATCH v2 06/11] fast-export: use a flex array to store anonymized entries Message-ID: <20200625194825.GF4029374@coredump.intra.peff.net> References: <20200625194802.GA4028913@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200625194802.GA4028913@coredump.intra.peff.net> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that we're using a separate keydata struct for hash lookups, we have more flexibility in how we allocate anonymized_entry structs. Let's push the "orig" key into a flex member within the struct. That should save us a few bytes of memory per entry (a pointer plus any malloc overhead), and may make lookups a little faster (since it's one less pointer to chase in the comparison function). Signed-off-by: Jeff King --- builtin/fast-export.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 5df2ada47d..99d4a2b404 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -120,8 +120,8 @@ static int has_unshown_parent(struct commit *commit) struct anonymized_entry { struct hashmap_entry hash; - const char *orig; const char *anon; + const char orig[FLEX_ARRAY]; }; struct anonymized_entry_key { @@ -170,9 +170,8 @@ static const char *anonymize_str(struct hashmap *map, ret = hashmap_get_entry(map, &key, hash, &key); if (!ret) { - ret = xmalloc(sizeof(*ret)); + FLEX_ALLOC_MEM(ret, orig, orig, len); hashmap_entry_init(&ret->hash, key.hash.hash); - ret->orig = xmemdupz(orig, len); ret->anon = generate(orig, len); hashmap_put(map, &ret->hash); }