Skip to content

Commit cb18386

Browse files
committed
khash: avoid using kh_val/kh_value directly
1 parent 76e671a commit cb18386

File tree

8 files changed

+23
-23
lines changed

8 files changed

+23
-23
lines changed

src/cache.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void cache_evict_entries(git_cache *cache)
128128
khiter_t pos = seed++ % git_oidmap_end(cache->map);
129129

130130
if (git_oidmap_has_data(cache->map, pos)) {
131-
git_cached_obj *evict = kh_val(cache->map, pos);
131+
git_cached_obj *evict = git_oidmap_value_at(cache->map, pos);
132132

133133
evict_count--;
134134
evicted_memory += evict->size;
@@ -158,7 +158,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
158158

159159
pos = git_oidmap_lookup_index(cache->map, oid);
160160
if (git_oidmap_valid_index(cache->map, pos)) {
161-
entry = kh_val(cache->map, pos);
161+
entry = git_oidmap_value_at(cache->map, pos);
162162

163163
if (flags && entry->flags != flags) {
164164
entry = NULL;
@@ -202,15 +202,15 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
202202
pos = kh_put(oid, cache->map, &entry->oid, &rval);
203203
if (rval >= 0) {
204204
kh_key(cache->map, pos) = &entry->oid;
205-
kh_val(cache->map, pos) = entry;
205+
git_oidmap_value_at(cache->map, pos) = entry;
206206
git_cached_obj_incref(entry);
207207
cache->used_memory += entry->size;
208208
git_atomic_ssize_add(&git_cache__current_storage, (ssize_t)entry->size);
209209
}
210210
}
211211
/* found */
212212
else {
213-
git_cached_obj *stored_entry = kh_val(cache->map, pos);
213+
git_cached_obj *stored_entry = git_oidmap_value_at(cache->map, pos);
214214

215215
if (stored_entry->flags == entry->flags) {
216216
git_cached_obj_decref(entry);
@@ -222,7 +222,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
222222
git_cached_obj_incref(entry);
223223

224224
kh_key(cache->map, pos) = &entry->oid;
225-
kh_val(cache->map, pos) = entry;
225+
git_oidmap_value_at(cache->map, pos) = entry;
226226
} else {
227227
/* NO OP */
228228
}

src/indexer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static int store_object(git_indexer *idx)
308308
}
309309

310310

311-
kh_value(idx->pack->idx_cache, k) = pentry;
311+
git_oidmap_value_at(idx->pack->idx_cache, k) = pentry;
312312

313313
git_oid_cpy(&entry->oid, &oid);
314314

@@ -356,7 +356,7 @@ static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_ent
356356
return -1;
357357
}
358358

359-
kh_value(idx->pack->idx_cache, k) = pentry;
359+
git_oidmap_value_at(idx->pack->idx_cache, k) = pentry;
360360

361361
/* Add the object to the list */
362362
if (git_vector_insert(&idx->objects, entry) < 0)

src/odb_mempack.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void
5858
obj->type = type;
5959

6060
kh_key(db->objects, pos) = &obj->oid;
61-
kh_val(db->objects, pos) = obj;
61+
git_oidmap_value_at(db->objects, pos) = obj;
6262

6363
if (type == GIT_OBJ_COMMIT) {
6464
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
8686
if (!git_oidmap_valid_index(db->objects, pos))
8787
return GIT_ENOTFOUND;
8888

89-
obj = kh_val(db->objects, pos);
89+
obj = git_oidmap_value_at(db->objects, pos);
9090

9191
*len_p = obj->len;
9292
*type_p = obj->type;
@@ -107,7 +107,7 @@ static int impl__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *
107107
if (!git_oidmap_valid_index(db->objects, pos))
108108
return GIT_ENOTFOUND;
109109

110-
obj = kh_val(db->objects, pos);
110+
obj = git_oidmap_value_at(db->objects, pos);
111111

112112
*len_p = obj->len;
113113
*type_p = obj->type;

src/pack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static void rehash(git_packbuilder *pb)
200200
git_oidmap_clear(pb->object_ix);
201201
for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) {
202202
pos = kh_put(oid, pb->object_ix, &po->id, &ret);
203-
kh_value(pb->object_ix, pos) = po;
203+
git_oidmap_value_at(pb->object_ix, pos) = po;
204204
}
205205
}
206206

@@ -252,7 +252,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
252252
return ret;
253253
}
254254
assert(ret != 0);
255-
kh_value(pb->object_ix, pos) = po;
255+
git_oidmap_value_at(pb->object_ix, pos) = po;
256256

257257
pb->done = false;
258258

@@ -520,7 +520,7 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
520520
if (!git_oidmap_valid_index(pb->object_ix, pos))
521521
return 0;
522522

523-
po = kh_value(pb->object_ix, pos);
523+
po = git_oidmap_value_at(pb->object_ix, pos);
524524
po->tagged = 1;
525525

526526
/* TODO: peel objects */

src/pack.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
119119

120120
k = git_offmap_lookup_index(cache->entries, offset);
121121
if (git_offmap_valid_index(cache->entries, k)) { /* found it */
122-
entry = kh_value(cache->entries, k);
122+
entry = git_offmap_value_at(cache->entries, k);
123123
git_atomic_inc(&entry->refcount);
124124
entry->last_usage = cache->use_ctr++;
125125
}
@@ -171,7 +171,7 @@ static int cache_add(
171171

172172
k = kh_put(off, cache->entries, offset, &error);
173173
assert(error != 0);
174-
kh_value(cache->entries, k) = entry;
174+
git_oidmap_value_at(cache->entries, k) = entry;
175175
cache->memory_used += entry->raw.len;
176176

177177
*cached_out = entry;
@@ -959,7 +959,7 @@ git_off_t get_delta_base(
959959
k = git_oidmap_lookup_index(p->idx_cache, &oid);
960960
if (git_oidmap_valid_index(p->idx_cache, k)) {
961961
*curpos += 20;
962-
return ((struct git_pack_entry *)kh_value(p->idx_cache, k))->offset;
962+
return ((struct git_pack_entry *)git_oidmap_value_at(p->idx_cache, k))->offset;
963963
} else {
964964
/* If we're building an index, don't try to find the pack
965965
* entry; we just haven't seen it yet. We'll make

src/revwalk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
2727
/* lookup and reserve space if not already present */
2828
pos = git_oidmap_lookup_index(walk->commits, oid);
2929
if (git_oidmap_valid_index(walk->commits, pos))
30-
return kh_value(walk->commits, pos);
30+
return git_oidmap_value_at(walk->commits, pos);
3131

3232
commit = git_commit_list_alloc_node(walk);
3333
if (commit == NULL)
@@ -37,7 +37,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
3737

3838
pos = kh_put(oid, walk->commits, &commit->oid, &ret);
3939
assert(ret != 0);
40-
kh_value(walk->commits, pos) = commit;
40+
git_oidmap_value_at(walk->commits, pos) = commit;
4141

4242
return commit;
4343
}

src/sortedcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key)
300300

301301
if (!error)
302302
kh_key(sc->map, pos) = item_key;
303-
kh_val(sc->map, pos) = item;
303+
git_strmap_value_at(sc->map, pos) = item;
304304

305305
error = git_vector_insert(&sc->items, item);
306306
if (error < 0)

tests/core/oidmap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void test_core_oidmap__basic(void)
3939
pos = kh_put(oid, map, &items[i].oid, &ret);
4040
cl_assert(ret != 0);
4141

42-
kh_val(map, pos) = &items[i];
42+
git_oidmap_value_at(map, pos) = &items[i];
4343
}
4444

4545

@@ -49,7 +49,7 @@ void test_core_oidmap__basic(void)
4949
pos = git_oidmap_lookup_index(map, &items[i].oid);
5050
cl_assert(git_oidmap_valid_index(map, pos));
5151

52-
cl_assert_equal_p(kh_val(map, pos), &items[i]);
52+
cl_assert_equal_p(git_oidmap_value_at(map, pos), &items[i]);
5353
}
5454

5555
git_oidmap_free(map);
@@ -93,7 +93,7 @@ void test_core_oidmap__hash_collision(void)
9393
pos = kh_put(oid, map, &items[i].oid, &ret);
9494
cl_assert(ret != 0);
9595

96-
kh_val(map, pos) = &items[i];
96+
git_oidmap_value_at(map, pos) = &items[i];
9797
}
9898

9999

@@ -103,7 +103,7 @@ void test_core_oidmap__hash_collision(void)
103103
pos = git_oidmap_lookup_index(map, &items[i].oid);
104104
cl_assert(git_oidmap_valid_index(map, pos));
105105

106-
cl_assert_equal_p(kh_val(map, pos), &items[i]);
106+
cl_assert_equal_p(git_oidmap_value_at(map, pos), &items[i]);
107107
}
108108

109109
git_oidmap_free(map);

0 commit comments

Comments
 (0)