summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-01-25 14:11:42 +0100
committerPatrick Steinhardt <ps@pks.im>2017-02-17 11:41:06 +0100
commit036daa59e94bbe1a14ccd8fa018618393a0c62fb (patch)
tree3489354e8437b00f4dbe7ef1809457b53bdf25db
parent9694d9ba794b36ebc9fc186c43464a08c2f84c4d (diff)
downloadlibgit2-036daa59e94bbe1a14ccd8fa018618393a0c62fb.tar.gz
khash: use `git_map_exists` where applicable
-rw-r--r--src/indexer.c4
-rw-r--r--src/odb_mempack.c7
-rw-r--r--src/oidmap.h2
-rw-r--r--src/pack-objects.c3
-rw-r--r--src/pack.c2
5 files changed, 6 insertions, 12 deletions
diff --git a/src/indexer.c b/src/indexer.c
index 8b5fa6efd..b5d5fd0d2 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -333,9 +333,7 @@ on_error:
GIT_INLINE(bool) has_entry(git_indexer *idx, git_oid *id)
{
- khiter_t k;
- k = kh_get(oid, idx->pack->idx_cache, id);
- return (k != kh_end(idx->pack->idx_cache));
+ return git_oidmap_exists(idx->pack->idx_cache, id);
}
static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_entry *pentry, git_off_t entry_start)
diff --git a/src/odb_mempack.c b/src/odb_mempack.c
index b9bdf0bb5..6aa9ad89a 100644
--- a/src/odb_mempack.c
+++ b/src/odb_mempack.c
@@ -72,13 +72,8 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void
static int impl__exists(git_odb_backend *backend, const git_oid *oid)
{
struct memory_packer_db *db = (struct memory_packer_db *)backend;
- khiter_t pos;
-
- pos = kh_get(oid, db->objects, oid);
- if (pos != kh_end(db->objects))
- return 1;
- return 0;
+ return git_oidmap_exists(db->objects, oid);
}
static int impl__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
diff --git a/src/oidmap.h b/src/oidmap.h
index 2cf208f53..5364862d2 100644
--- a/src/oidmap.h
+++ b/src/oidmap.h
@@ -36,6 +36,8 @@ GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
#define git_oidmap_lookup_index(h, k) kh_get(oid, h, k)
#define git_oidmap_valid_index(h, idx) (idx != kh_end(h))
+#define git_oidmap_exists(h, k) (kh_get(oid, h, k) != kh_end(h))
+
#define git_oidmap_value_at(h, idx) kh_val(h, idx)
#define git_oidmap_insert(h, key, val, rval) do { \
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 2e5de98ab..203816710 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -216,8 +216,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
/* If the object already exists in the hash table, then we don't
* have any work to do */
- pos = kh_get(oid, pb->object_ix, oid);
- if (pos != kh_end(pb->object_ix))
+ if (git_oidmap_exists(pb->object_ix, oid))
return 0;
if (pb->nr_objects >= pb->nr_alloc) {
diff --git a/src/pack.c b/src/pack.c
index 0f2fa5cdd..8a204342d 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -164,7 +164,7 @@ static int cache_add(
return -1;
}
/* Add it to the cache if nobody else has */
- exists = kh_get(off, cache->entries, offset) != kh_end(cache->entries);
+ exists = git_offmap_exists(cache->entries, offset);
if (!exists) {
while (cache->memory_used + base->len > cache->memory_limit)
free_lowest_entry(cache);