khash: avoid using `kh_val`/`kh_value` directly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
diff --git a/src/cache.c b/src/cache.c
index ae42216..c5f576a 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -128,7 +128,7 @@ static void cache_evict_entries(git_cache *cache)
khiter_t pos = seed++ % git_oidmap_end(cache->map);
if (git_oidmap_has_data(cache->map, pos)) {
- git_cached_obj *evict = kh_val(cache->map, pos);
+ git_cached_obj *evict = git_oidmap_value_at(cache->map, pos);
evict_count--;
evicted_memory += evict->size;
@@ -158,7 +158,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
pos = git_oidmap_lookup_index(cache->map, oid);
if (git_oidmap_valid_index(cache->map, pos)) {
- entry = kh_val(cache->map, pos);
+ entry = git_oidmap_value_at(cache->map, pos);
if (flags && entry->flags != flags) {
entry = NULL;
@@ -202,7 +202,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
pos = kh_put(oid, cache->map, &entry->oid, &rval);
if (rval >= 0) {
kh_key(cache->map, pos) = &entry->oid;
- kh_val(cache->map, pos) = entry;
+ git_oidmap_value_at(cache->map, pos) = entry;
git_cached_obj_incref(entry);
cache->used_memory += entry->size;
git_atomic_ssize_add(&git_cache__current_storage, (ssize_t)entry->size);
@@ -210,7 +210,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
}
/* found */
else {
- git_cached_obj *stored_entry = kh_val(cache->map, pos);
+ git_cached_obj *stored_entry = git_oidmap_value_at(cache->map, pos);
if (stored_entry->flags == entry->flags) {
git_cached_obj_decref(entry);
@@ -222,7 +222,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
git_cached_obj_incref(entry);
kh_key(cache->map, pos) = &entry->oid;
- kh_val(cache->map, pos) = entry;
+ git_oidmap_value_at(cache->map, pos) = entry;
} else {
/* NO OP */
}
diff --git a/src/indexer.c b/src/indexer.c
index b5d5fd0..303dd7c 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -308,7 +308,7 @@ static int store_object(git_indexer *idx)
}
- kh_value(idx->pack->idx_cache, k) = pentry;
+ git_oidmap_value_at(idx->pack->idx_cache, k) = pentry;
git_oid_cpy(&entry->oid, &oid);
@@ -356,7 +356,7 @@ static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_ent
return -1;
}
- kh_value(idx->pack->idx_cache, k) = pentry;
+ git_oidmap_value_at(idx->pack->idx_cache, k) = pentry;
/* Add the object to the list */
if (git_vector_insert(&idx->objects, entry) < 0)
diff --git a/src/odb_mempack.c b/src/odb_mempack.c
index b55ce73..1b8987e 100644
--- a/src/odb_mempack.c
+++ b/src/odb_mempack.c
@@ -58,7 +58,7 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void
obj->type = type;
kh_key(db->objects, pos) = &obj->oid;
- kh_val(db->objects, pos) = obj;
+ git_oidmap_value_at(db->objects, pos) = obj;
if (type == GIT_OBJ_COMMIT) {
struct memobject **store = git_array_alloc(db->commits);
@@ -86,7 +86,7 @@ static int impl__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb
if (!git_oidmap_valid_index(db->objects, pos))
return GIT_ENOTFOUND;
- obj = kh_val(db->objects, pos);
+ obj = git_oidmap_value_at(db->objects, pos);
*len_p = obj->len;
*type_p = obj->type;
@@ -107,7 +107,7 @@ static int impl__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *
if (!git_oidmap_valid_index(db->objects, pos))
return GIT_ENOTFOUND;
- obj = kh_val(db->objects, pos);
+ obj = git_oidmap_value_at(db->objects, pos);
*len_p = obj->len;
*type_p = obj->type;
diff --git a/src/pack-objects.c b/src/pack-objects.c
index e463820..01286fa 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -200,7 +200,7 @@ static void rehash(git_packbuilder *pb)
git_oidmap_clear(pb->object_ix);
for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) {
pos = kh_put(oid, pb->object_ix, &po->id, &ret);
- kh_value(pb->object_ix, pos) = po;
+ git_oidmap_value_at(pb->object_ix, pos) = po;
}
}
@@ -252,7 +252,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
return ret;
}
assert(ret != 0);
- kh_value(pb->object_ix, pos) = po;
+ git_oidmap_value_at(pb->object_ix, pos) = po;
pb->done = false;
@@ -520,7 +520,7 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
if (!git_oidmap_valid_index(pb->object_ix, pos))
return 0;
- po = kh_value(pb->object_ix, pos);
+ po = git_oidmap_value_at(pb->object_ix, pos);
po->tagged = 1;
/* TODO: peel objects */
diff --git a/src/pack.c b/src/pack.c
index 43ef098..4c2b9eb 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -119,7 +119,7 @@ static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
k = git_offmap_lookup_index(cache->entries, offset);
if (git_offmap_valid_index(cache->entries, k)) { /* found it */
- entry = kh_value(cache->entries, k);
+ entry = git_offmap_value_at(cache->entries, k);
git_atomic_inc(&entry->refcount);
entry->last_usage = cache->use_ctr++;
}
@@ -171,7 +171,7 @@ static int cache_add(
k = kh_put(off, cache->entries, offset, &error);
assert(error != 0);
- kh_value(cache->entries, k) = entry;
+ git_oidmap_value_at(cache->entries, k) = entry;
cache->memory_used += entry->raw.len;
*cached_out = entry;
@@ -959,7 +959,7 @@ git_off_t get_delta_base(
k = git_oidmap_lookup_index(p->idx_cache, &oid);
if (git_oidmap_valid_index(p->idx_cache, k)) {
*curpos += 20;
- return ((struct git_pack_entry *)kh_value(p->idx_cache, k))->offset;
+ return ((struct git_pack_entry *)git_oidmap_value_at(p->idx_cache, k))->offset;
} else {
/* If we're building an index, don't try to find the pack
* entry; we just haven't seen it yet. We'll make
diff --git a/src/revwalk.c b/src/revwalk.c
index 7526665..32a4ff9 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -27,7 +27,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
/* lookup and reserve space if not already present */
pos = git_oidmap_lookup_index(walk->commits, oid);
if (git_oidmap_valid_index(walk->commits, pos))
- return kh_value(walk->commits, pos);
+ return git_oidmap_value_at(walk->commits, pos);
commit = git_commit_list_alloc_node(walk);
if (commit == NULL)
@@ -37,7 +37,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
pos = kh_put(oid, walk->commits, &commit->oid, &ret);
assert(ret != 0);
- kh_value(walk->commits, pos) = commit;
+ git_oidmap_value_at(walk->commits, pos) = commit;
return commit;
}
diff --git a/src/sortedcache.c b/src/sortedcache.c
index c5e338f..48e8b6c 100644
--- a/src/sortedcache.c
+++ b/src/sortedcache.c
@@ -300,7 +300,7 @@ int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key)
if (!error)
kh_key(sc->map, pos) = item_key;
- kh_val(sc->map, pos) = item;
+ git_strmap_value_at(sc->map, pos) = item;
error = git_vector_insert(&sc->items, item);
if (error < 0)
diff --git a/tests/core/oidmap.c b/tests/core/oidmap.c
index 2255e39..61d75e9 100644
--- a/tests/core/oidmap.c
+++ b/tests/core/oidmap.c
@@ -39,7 +39,7 @@ void test_core_oidmap__basic(void)
pos = kh_put(oid, map, &items[i].oid, &ret);
cl_assert(ret != 0);
- kh_val(map, pos) = &items[i];
+ git_oidmap_value_at(map, pos) = &items[i];
}
@@ -49,7 +49,7 @@ void test_core_oidmap__basic(void)
pos = git_oidmap_lookup_index(map, &items[i].oid);
cl_assert(git_oidmap_valid_index(map, pos));
- cl_assert_equal_p(kh_val(map, pos), &items[i]);
+ cl_assert_equal_p(git_oidmap_value_at(map, pos), &items[i]);
}
git_oidmap_free(map);
@@ -93,7 +93,7 @@ void test_core_oidmap__hash_collision(void)
pos = kh_put(oid, map, &items[i].oid, &ret);
cl_assert(ret != 0);
- kh_val(map, pos) = &items[i];
+ git_oidmap_value_at(map, pos) = &items[i];
}
@@ -103,7 +103,7 @@ void test_core_oidmap__hash_collision(void)
pos = git_oidmap_lookup_index(map, &items[i].oid);
cl_assert(git_oidmap_valid_index(map, pos));
- cl_assert_equal_p(kh_val(map, pos), &items[i]);
+ cl_assert_equal_p(git_oidmap_value_at(map, pos), &items[i]);
}
git_oidmap_free(map);