@matheusbsbs / matheus-bagliano / commits / 55b01456a9
Fork 0

fast-export: use a flex array to store anonymized entries

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>

Jeff King committed Jun 23, 2020 at 11:24 UTC 55b01456a95ac8d92b04d58b874459f3bf70ad2c
1 file changed +2 -3
builtin/fast-export.c
+2 -3
@@ -120,8 +120,8 @@ static int has_unshown_parent(struct commit *commit)
120
121 struct anonymized_entry {
122 struct hashmap_entry hash;
123 - const char *orig;
123 const char *anon;
124 + const char orig[FLEX_ARRAY];
125 };
126
127 struct anonymized_entry_key {
@@ -170,9 +170,8 @@ static const char *anonymize_str(struct hashmap *map,
170 ret = hashmap_get_entry(map, &key, hash, &key);
171
172 if (!ret) {
173 - ret = xmalloc(sizeof(*ret));
173 + FLEX_ALLOC_MEM(ret, orig, orig, len);
174 hashmap_entry_init(&ret->hash, key.hash.hash);
175 - ret->orig = xmemdupz(orig, len);
175 ret->anon = generate(orig, len);
176 hashmap_put(map, &ret->hash);
177 }