diff options
| author | Patrick Steinhardt <ps@pks.im> | 2018-12-01 08:50:36 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 13:16:48 +0100 |
| commit | 84a089da3701db370b2c77e6866abe3a5065c542 (patch) | |
| tree | a70b47efb1c29ab0c779fbb7f25447a33d9d0dce /src/strmap.c | |
| parent | 8da93944f3d3c271ea7a2ec035c6ea48654fa71e (diff) | |
| download | libgit2-84a089da3701db370b2c77e6866abe3a5065c542.tar.gz | |
maps: provide return value when deleting entries
Currently, the delete functions of maps do not provide a return value. Like
this, it is impossible to tell whether the entry has really been deleted or not.
Change the implementation to provide either a return value of zero if the entry
has been successfully deleted or `GIT_ENOTFOUND` if the key could not be found.
Convert callers to the `delete_at` functions to instead use this higher-level
interface.
Diffstat (limited to 'src/strmap.c')
| -rw-r--r-- | src/strmap.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/strmap.c b/src/strmap.c index 4c1818a0e..ffdf6f13d 100644 --- a/src/strmap.c +++ b/src/strmap.c @@ -67,6 +67,15 @@ int git_strmap_set(git_strmap *map, const char *key, void *value) return 0; } +int git_strmap_delete(git_strmap *map, const char *key) +{ + khiter_t idx = git_strmap_lookup_index(map, key); + if (!git_strmap_valid_index(map, idx)) + return GIT_ENOTFOUND; + git_strmap_delete_at(map, idx); + return 0; +} + size_t git_strmap_lookup_index(git_strmap *map, const char *key) { return kh_get(str, map, key); @@ -128,13 +137,6 @@ void git_strmap_insert(git_strmap *map, const char *key, void *value, int *rval) } } -void git_strmap_delete(git_strmap *map, const char *key) -{ - khiter_t idx = git_strmap_lookup_index(map, key); - if (git_strmap_valid_index(map, idx)) - git_strmap_delete_at(map, idx); -} - size_t git_strmap_begin(git_strmap *map) { GIT_UNUSED(map); |
