diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-01-23 10:42:46 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 13:16:48 +0100 |
| commit | 351eeff3b2a666b8ead5302c1130629597438df6 (patch) | |
| tree | 5b494d3e5912949980fbbbb4945da4c2eb630aa1 /src/idxmap.c | |
| parent | bda0839734bad8351e1dbc9c7beb8ae1f00d831e (diff) | |
| download | libgit2-351eeff3b2a666b8ead5302c1130629597438df6.tar.gz | |
maps: use uniform lifecycle management functions
Currently, the lifecycle functions for maps (allocation, deallocation, resize)
are not named in a uniform way and do not have a uniform function signature.
Rename the functions to fix that, and stick to libgit2's naming scheme of saying
`git_foo_new`. This results in the following new interface for allocation:
- `int git_<t>map_new(git_<t>map **out)` to allocate a new map, returning an
error code if we ran out of memory
- `void git_<t>map_free(git_<t>map *map)` to free a map
- `void git_<t>map_clear(git<t>map *map)` to remove all entries from a map
This commit also fixes all existing callers.
Diffstat (limited to 'src/idxmap.c')
| -rw-r--r-- | src/idxmap.c | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/src/idxmap.c b/src/idxmap.c index 3a5fc105a..8ed9849c9 100644 --- a/src/idxmap.c +++ b/src/idxmap.c @@ -32,26 +32,42 @@ static kh_inline khint_t idxentry_hash(const git_index_entry *e) __KHASH_IMPL(idx, static kh_inline, const git_index_entry *, git_index_entry *, 1, idxentry_hash, idxentry_equal) __KHASH_IMPL(idxicase, static kh_inline, const git_index_entry *, git_index_entry *, 1, idxentry_hash, idxentry_icase_equal) -int git_idxmap_alloc(git_idxmap **map) +int git_idxmap_new(git_idxmap **out) { - if ((*map = kh_init(idx)) == NULL) { - git_error_set_oom(); - return -1; - } + *out = kh_init(idx); + GIT_ERROR_CHECK_ALLOC(*out); return 0; } -int git_idxmap_icase_alloc(git_idxmap_icase **map) +int git_idxmap_icase_new(git_idxmap_icase **out) { - if ((*map = kh_init(idxicase)) == NULL) { - git_error_set_oom(); - return -1; - } + *out = kh_init(idxicase); + GIT_ERROR_CHECK_ALLOC(*out); return 0; } +void git_idxmap_free(git_idxmap *map) +{ + kh_destroy(idx, map); +} + +void git_idxmap_icase_free(git_idxmap_icase *map) +{ + kh_destroy(idxicase, map); +} + +void git_idxmap_clear(git_idxmap *map) +{ + kh_clear(idx, map); +} + +void git_idxmap_icase_clear(git_idxmap_icase *map) +{ + kh_clear(idxicase, map); +} + void git_idxmap_insert(git_idxmap *map, const git_index_entry *key, void *value, int *rval) { khiter_t idx = kh_put(idx, map, key, rval); @@ -109,26 +125,6 @@ void git_idxmap_icase_resize(git_idxmap_icase *map, size_t size) kh_resize(idxicase, map, size); } -void git_idxmap_free(git_idxmap *map) -{ - kh_destroy(idx, map); -} - -void git_idxmap_icase_free(git_idxmap_icase *map) -{ - kh_destroy(idxicase, map); -} - -void git_idxmap_clear(git_idxmap *map) -{ - kh_clear(idx, map); -} - -void git_idxmap_icase_clear(git_idxmap_icase *map) -{ - kh_clear(idxicase, map); -} - void git_idxmap_delete_at(git_idxmap *map, size_t idx) { kh_del(idx, map, idx); |
