diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-01-23 10:44:02 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 13:16:48 +0100 |
commit | ef507bc7bdd736d2379a0d0614b3db1341d77187 (patch) | |
tree | a441206d2eef9ddfa3784b361910a9f03d1a5bf6 /src/diff_driver.c | |
parent | 7e926ef306166993131628b41a13f2b26aaf43de (diff) | |
download | libgit2-ef507bc7bdd736d2379a0d0614b3db1341d77187.tar.gz |
strmap: introduce `git_strmap_get` and use it throughout the tree
The current way of looking up an entry from a map is tightly coupled with the
map implementation, as one first has to look up the index of the key and then
retrieve the associated value by using the index. As a caller, you usually do
not care about any indices at all, though, so this is more complicated than
really necessary. Furthermore, it invites for errors to happen if the correct
error checking sequence is not being followed.
Introduce a new high-level function `git_strmap_get` that takes a map and a key
and returns a pointer to the associated value if such a key exists. Otherwise,
a `NULL` pointer is returned. Adjust all callers that can trivially be
converted.
Diffstat (limited to 'src/diff_driver.c')
-rw-r--r-- | src/diff_driver.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/diff_driver.c b/src/diff_driver.c index 9bc266e02..342ac247a 100644 --- a/src/diff_driver.c +++ b/src/diff_driver.c @@ -233,8 +233,8 @@ static int git_diff_driver_load( { int error = 0; git_diff_driver_registry *reg; - git_diff_driver *drv = NULL; - size_t namelen, pos; + git_diff_driver *drv; + size_t namelen; git_config *cfg = NULL; git_buf name = GIT_BUF_INIT; git_config_entry *ce = NULL; @@ -243,9 +243,8 @@ static int git_diff_driver_load( if ((reg = git_repository_driver_registry(repo)) == NULL) return -1; - pos = git_strmap_lookup_index(reg->drivers, driver_name); - if (git_strmap_valid_index(reg->drivers, pos)) { - *out = git_strmap_value_at(reg->drivers, pos); + if ((drv = git_strmap_get(reg->drivers, driver_name)) != NULL) { + *out = drv; return 0; } |