summaryrefslogtreecommitdiff
path: root/strmap.h
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2020-11-11 20:02:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-11-11 20:55:27 (GMT)
commit23a276a9c4c8945aadbc323e12c970816eb43c27 (patch)
treebad77bc27adce523a377cca4a5af1f173c2649f8 /strmap.h
parenta208ec1f0b654390ad06372c53b7ffe785052d98 (diff)
downloadgit-23a276a9c4c8945aadbc323e12c970816eb43c27.zip
git-23a276a9c4c8945aadbc323e12c970816eb43c27.tar.gz
git-23a276a9c4c8945aadbc323e12c970816eb43c27.tar.bz2
strmap: take advantage of FLEXPTR_ALLOC_STR when relevant
By default, we do not use a mempool and strdup_strings is true; in this case, we can avoid both an extra allocation and an extra free by just over-allocating for the strmap_entry leaving enough space at the end to copy the key. FLEXPTR_ALLOC_STR exists for exactly this purpose, so make use of it. Also, adjust the case when we are using a memory pool and strdup_strings is true to just do one allocation from the memory pool instead of two so that the strmap_clear() and strmap_remove() code can just avoid freeing the key in all cases. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strmap.h')
-rw-r--r--strmap.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/strmap.h b/strmap.h
index 8745b7c..c4c1044 100644
--- a/strmap.h
+++ b/strmap.h
@@ -14,6 +14,7 @@ struct strmap_entry {
struct hashmap_entry ent;
const char *key;
void *value;
+ /* strmap_entry may be allocated extra space to store the key at end */
};
int cmp_strmap_entry(const void *hashmap_cmp_fn_data,