summaryrefslogtreecommitdiff
path: root/src/pack.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-11-30 18:28:05 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 13:16:48 +0100
commitaa2456239b4644c43d3cc9e002ed718e5078e7cc (patch)
tree9344afe02269f8b49ca33b180659bbc9d723486c /src/pack.c
parent2e0a304839764236654e73d38fa380b317a3fac1 (diff)
downloadlibgit2-aa2456239b4644c43d3cc9e002ed718e5078e7cc.tar.gz
offmap: introduce high-level getter for values
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_offmap_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/pack.c')
-rw-r--r--src/pack.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/pack.c b/src/pack.c
index 650d20346..ab78d3f61 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -111,15 +111,12 @@ static int cache_init(git_pack_cache *cache)
static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
{
- git_pack_cache_entry *entry = NULL;
- size_t k;
+ git_pack_cache_entry *entry;
if (git_mutex_lock(&cache->lock) < 0)
return NULL;
- k = git_offmap_lookup_index(cache->entries, offset);
- if (git_offmap_valid_index(cache->entries, k)) { /* found it */
- entry = git_offmap_value_at(cache->entries, k);
+ if ((entry = git_offmap_get(cache->entries, offset)) != NULL) {
git_atomic_inc(&entry->refcount);
entry->last_usage = cache->use_ctr++;
}