summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-01-25 14:14:12 +0100
committerPatrick Steinhardt <ps@pks.im>2017-02-17 11:41:06 +0100
commit64e46dc3b54bb7071b5d21e16db8ebf5a44eb8ed (patch)
tree14ed6189acd384bb3b7f8ae77fd9178a98d86aec
parent036daa59e94bbe1a14ccd8fa018618393a0c62fb (diff)
downloadlibgit2-64e46dc3b54bb7071b5d21e16db8ebf5a44eb8ed.tar.gz
khash: avoid using `kh_end` directly
-rw-r--r--src/cache.c6
-rw-r--r--src/odb_mempack.c4
-rw-r--r--src/oidmap.h3
-rw-r--r--src/pack-objects.c2
-rw-r--r--src/pack.c4
-rw-r--r--src/revwalk.c2
-rw-r--r--tests/core/oidmap.c8
7 files changed, 16 insertions, 13 deletions
diff --git a/src/cache.c b/src/cache.c
index e7a565e05..7ababc9df 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -125,7 +125,7 @@ static void cache_evict_entries(git_cache *cache)
}
while (evict_count > 0) {
- khiter_t pos = seed++ % kh_end(cache->map);
+ khiter_t pos = seed++ % git_oidmap_end(cache->map);
if (kh_exist(cache->map, pos)) {
git_cached_obj *evict = kh_val(cache->map, pos);
@@ -157,7 +157,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
return NULL;
pos = kh_get(oid, cache->map, oid);
- if (pos != kh_end(cache->map)) {
+ if (git_oidmap_valid_index(cache->map, pos)) {
entry = kh_val(cache->map, pos);
if (flags && entry->flags != flags) {
@@ -196,7 +196,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
pos = kh_get(oid, cache->map, &entry->oid);
/* not found */
- if (pos == kh_end(cache->map)) {
+ if (!git_oidmap_valid_index(cache->map, pos)) {
int rval;
pos = kh_put(oid, cache->map, &entry->oid, &rval);
diff --git a/src/odb_mempack.c b/src/odb_mempack.c
index 6aa9ad89a..fc5e0f1d4 100644
--- a/src/odb_mempack.c
+++ b/src/odb_mempack.c
@@ -83,7 +83,7 @@ static int impl__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb
khiter_t pos;
pos = kh_get(oid, db->objects, oid);
- if (pos == kh_end(db->objects))
+ if (!git_oidmap_valid_index(db->objects, pos))
return GIT_ENOTFOUND;
obj = kh_val(db->objects, pos);
@@ -104,7 +104,7 @@ static int impl__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *
khiter_t pos;
pos = kh_get(oid, db->objects, oid);
- if (pos == kh_end(db->objects))
+ if (!git_oidmap_valid_index(db->objects, pos))
return GIT_ENOTFOUND;
obj = kh_val(db->objects, pos);
diff --git a/src/oidmap.h b/src/oidmap.h
index 5364862d2..c0c45027d 100644
--- a/src/oidmap.h
+++ b/src/oidmap.h
@@ -49,6 +49,9 @@ GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
#define git_oidmap_foreach_value kh_foreach_value
+#define git_oidmap_begin kh_begin
+#define git_oidmap_end kh_end
+
#define git_oidmap_size(h) kh_size(h)
#define git_oidmap_clear(h) kh_clear(oid, h)
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 203816710..3517de479 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -517,7 +517,7 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
GIT_UNUSED(name);
pos = kh_get(oid, pb->object_ix, oid);
- if (pos == kh_end(pb->object_ix))
+ if (!git_oidmap_valid_index(pb->object_ix, pos))
return 0;
po = kh_value(pb->object_ix, pos);
diff --git a/src/pack.c b/src/pack.c
index 8a204342d..e23d50110 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -118,7 +118,7 @@ static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
return NULL;
k = kh_get(off, cache->entries, offset);
- if (k != kh_end(cache->entries)) { /* found it */
+ if (git_offmap_valid_index(cache->entries, k)) { /* found it */
entry = kh_value(cache->entries, k);
git_atomic_inc(&entry->refcount);
entry->last_usage = cache->use_ctr++;
@@ -957,7 +957,7 @@ git_off_t get_delta_base(
git_oid_fromraw(&oid, base_info);
k = kh_get(oid, p->idx_cache, &oid);
- if (k != kh_end(p->idx_cache)) {
+ if (git_oidmap_valid_index(p->idx_cache, k)) {
*curpos += 20;
return ((struct git_pack_entry *)kh_value(p->idx_cache, k))->offset;
} else {
diff --git a/src/revwalk.c b/src/revwalk.c
index c5fdb7ee3..8805aa8fa 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -26,7 +26,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
/* lookup and reserve space if not already present */
pos = kh_get(oid, walk->commits, oid);
- if (pos != kh_end(walk->commits))
+ if (git_oidmap_valid_index(walk->commits, pos))
return kh_value(walk->commits, pos);
commit = git_commit_list_alloc_node(walk);
diff --git a/tests/core/oidmap.c b/tests/core/oidmap.c
index 556a6ca4a..aea069843 100644
--- a/tests/core/oidmap.c
+++ b/tests/core/oidmap.c
@@ -34,7 +34,7 @@ void test_core_oidmap__basic(void)
int ret;
pos = kh_get(oid, map, &items[i].oid);
- cl_assert(pos == kh_end(map));
+ cl_assert(!git_oidmap_valid_index(map, pos));
pos = kh_put(oid, map, &items[i].oid, &ret);
cl_assert(ret != 0);
@@ -47,7 +47,7 @@ void test_core_oidmap__basic(void)
khiter_t pos;
pos = kh_get(oid, map, &items[i].oid);
- cl_assert(pos != kh_end(map));
+ cl_assert(git_oidmap_valid_index(map, pos));
cl_assert_equal_p(kh_val(map, pos), &items[i]);
}
@@ -88,7 +88,7 @@ void test_core_oidmap__hash_collision(void)
int ret;
pos = kh_get(oid, map, &items[i].oid);
- cl_assert(pos == kh_end(map));
+ cl_assert(!git_oidmap_valid_index(map, pos));
pos = kh_put(oid, map, &items[i].oid, &ret);
cl_assert(ret != 0);
@@ -101,7 +101,7 @@ void test_core_oidmap__hash_collision(void)
khiter_t pos;
pos = kh_get(oid, map, &items[i].oid);
- cl_assert(pos != kh_end(map));
+ cl_assert(git_oidmap_valid_index(map, pos));
cl_assert_equal_p(kh_val(map, pos), &items[i]);
}