]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fast-export: use a flex array to store anonymized entries
authorJeff King <peff@peff.net>
Tue, 23 Jun 2020 15:24:58 +0000 (11:24 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Jun 2020 02:56:26 +0000 (19:56 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-export.c

index 5df2ada47d03a865b8279c14cc860d7f240262c6..99d4a2b404063c99e4327697c2f9449a7451e4e0 100644 (file)
@@ -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);
        }