summaryrefslogtreecommitdiff
path: root/strmap.h
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2020-11-11 20:02:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-11-11 20:55:27 (GMT)
commita208ec1f0b654390ad06372c53b7ffe785052d98 (patch)
treed4854d3c5d85e077607c64d9b4d9b02e2fa2acdd /strmap.h
parent1201eb628ac753af5751258466df5f964bdc9f17 (diff)
downloadgit-a208ec1f0b654390ad06372c53b7ffe785052d98.zip
git-a208ec1f0b654390ad06372c53b7ffe785052d98.tar.gz
git-a208ec1f0b654390ad06372c53b7ffe785052d98.tar.bz2
strmap: enable allocations to come from a mem_pool
For heavy users of strmaps, allowing the keys and entries to be allocated from a memory pool can provide significant overhead savings. Add an option to strmap_init_with_options() to specify a memory pool. 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.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/strmap.h b/strmap.h
index c8c4d7c..8745b7c 100644
--- a/strmap.h
+++ b/strmap.h
@@ -3,8 +3,10 @@
#include "hashmap.h"
+struct mem_pool;
struct strmap {
struct hashmap map;
+ struct mem_pool *pool;
unsigned int strdup_strings:1;
};
@@ -37,9 +39,10 @@ void strmap_init(struct strmap *map);
/*
* Same as strmap_init, but for those who want to control the memory management
- * carefully instead of using the default of strdup_strings=1.
+ * carefully instead of using the default of strdup_strings=1 and pool=NULL.
*/
void strmap_init_with_options(struct strmap *map,
+ struct mem_pool *pool,
int strdup_strings);
/*
@@ -137,9 +140,10 @@ static inline void strintmap_init(struct strintmap *map, int default_value)
static inline void strintmap_init_with_options(struct strintmap *map,
int default_value,
+ struct mem_pool *pool,
int strdup_strings)
{
- strmap_init_with_options(&map->map, strdup_strings);
+ strmap_init_with_options(&map->map, pool, strdup_strings);
map->default_value = default_value;
}
@@ -221,9 +225,10 @@ static inline void strset_init(struct strset *set)
}
static inline void strset_init_with_options(struct strset *set,
+ struct mem_pool *pool,
int strdup_strings)
{
- strmap_init_with_options(&set->map, strdup_strings);
+ strmap_init_with_options(&set->map, pool, strdup_strings);
}
static inline void strset_clear(struct strset *set)