Skip to content

Commit 55b0145

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0f6564 commit 55b0145

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

builtin/fast-export.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ static int has_unshown_parent(struct commit *commit)
120120

121121
struct anonymized_entry {
122122
struct hashmap_entry hash;
123-
const char *orig;
124123
const char *anon;
124+
const char orig[FLEX_ARRAY];
125125
};
126126

127127
struct anonymized_entry_key {
@@ -170,9 +170,8 @@ static const char *anonymize_str(struct hashmap *map,
170170
ret = hashmap_get_entry(map, &key, hash, &key);
171171

172172
if (!ret) {
173-
ret = xmalloc(sizeof(*ret));
173+
FLEX_ALLOC_MEM(ret, orig, orig, len);
174174
hashmap_entry_init(&ret->hash, key.hash.hash);
175-
ret->orig = xmemdupz(orig, len);
176175
ret->anon = generate(orig, len);
177176
hashmap_put(map, &ret->hash);
178177
}

0 commit comments

Comments
 (0)