mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
strmap: split create_entry() out of strmap_put()
This will facilitate adding entries to a strmap subtype in ways that differ slightly from that of strmap_put(). Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
4fa1d501f7
commit
6abd22065c
27
strmap.c
27
strmap.c
@ -70,15 +70,11 @@ void strmap_partial_clear(struct strmap *map, int free_values)
|
||||
hashmap_partial_clear(&map->map);
|
||||
}
|
||||
|
||||
void *strmap_put(struct strmap *map, const char *str, void *data)
|
||||
static struct strmap_entry *create_entry(struct strmap *map,
|
||||
const char *str,
|
||||
void *data)
|
||||
{
|
||||
struct strmap_entry *entry = find_strmap_entry(map, str);
|
||||
void *old = NULL;
|
||||
|
||||
if (entry) {
|
||||
old = entry->value;
|
||||
entry->value = data;
|
||||
} else {
|
||||
struct strmap_entry *entry;
|
||||
const char *key = str;
|
||||
|
||||
entry = xmalloc(sizeof(*entry));
|
||||
@ -88,11 +84,24 @@ void *strmap_put(struct strmap *map, const char *str, void *data)
|
||||
key = xstrdup(str);
|
||||
entry->key = key;
|
||||
entry->value = data;
|
||||
hashmap_add(&map->map, &entry->ent);
|
||||
return entry;
|
||||
}
|
||||
|
||||
void *strmap_put(struct strmap *map, const char *str, void *data)
|
||||
{
|
||||
struct strmap_entry *entry = find_strmap_entry(map, str);
|
||||
|
||||
if (entry) {
|
||||
void *old = entry->value;
|
||||
entry->value = data;
|
||||
return old;
|
||||
}
|
||||
|
||||
entry = create_entry(map, str, data);
|
||||
hashmap_add(&map->map, &entry->ent);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct strmap_entry *strmap_get_entry(struct strmap *map, const char *str)
|
||||
{
|
||||
return find_strmap_entry(map, str);
|
||||
|
Loading…
Reference in New Issue
Block a user