Skip to content

Commit 9694d9b

Browse files
committed
khash: avoid using kh_foreach/kh_foreach_value directly
1 parent 63e914c commit 9694d9b

File tree

6 files changed

+17
-32
lines changed

6 files changed

+17
-32
lines changed

src/cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void git_cache_dump_stats(git_cache *cache)
5353
printf("Cache %p: %"PRIuZ" items cached, %"PRIdZ" bytes\n",
5454
cache, git_cache_size(cache), cache->used_memory);
5555

56-
kh_foreach_value(cache->map, object, {
56+
git_oidmap_foreach_value(cache->map, object, {
5757
char oid_str[9];
5858
printf(" %s%c %s (%"PRIuZ")\n",
5959
git_object_type2string(object->type),
@@ -84,7 +84,7 @@ static void clear_cache(git_cache *cache)
8484
if (git_cache_size(cache) == 0)
8585
return;
8686

87-
kh_foreach_value(cache->map, evict, {
87+
git_oidmap_foreach_value(cache->map, evict, {
8888
git_cached_obj_decref(evict);
8989
});
9090

src/indexer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,9 @@ void git_indexer_free(git_indexer *idx)
11061106

11071107
if (idx->pack->idx_cache) {
11081108
struct git_pack_entry *pentry;
1109-
kh_foreach_value(
1110-
idx->pack->idx_cache, pentry, { git__free(pentry); });
1109+
git_oidmap_foreach_value(idx->pack->idx_cache, pentry, {
1110+
git__free(pentry);
1111+
});
11111112

11121113
git_oidmap_free(idx->pack->idx_cache);
11131114
}

src/odb_mempack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void git_mempack_reset(git_odb_backend *_backend)
149149
struct memory_packer_db *db = (struct memory_packer_db *)_backend;
150150
struct memobject *object = NULL;
151151

152-
kh_foreach_value(db->objects, object, {
152+
git_oidmap_foreach_value(db->objects, object, {
153153
git__free(object);
154154
});
155155

src/pack.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,12 @@ static void free_cache_object(void *o)
7878

7979
static void cache_free(git_pack_cache *cache)
8080
{
81-
khiter_t k;
81+
git_pack_cache_entry *entry;
8282

8383
if (cache->entries) {
84-
for (k = kh_begin(cache->entries); k != kh_end(cache->entries); k++) {
85-
if (kh_exist(cache->entries, k))
86-
free_cache_object(kh_value(cache->entries, k));
87-
}
84+
git_offmap_foreach_value(cache->entries, entry, {
85+
free_cache_object(entry);
86+
});
8887

8988
git_offmap_free(cache->entries);
9089
cache->entries = NULL;
@@ -135,18 +134,13 @@ static void free_lowest_entry(git_pack_cache *cache)
135134
git_pack_cache_entry *entry;
136135
khiter_t k;
137136

138-
for (k = kh_begin(cache->entries); k != kh_end(cache->entries); k++) {
139-
if (!kh_exist(cache->entries, k))
140-
continue;
141-
142-
entry = kh_value(cache->entries, k);
143-
137+
git_offmap_foreach(cache->entries, k, entry, {
144138
if (entry && entry->refcount.val == 0) {
145139
cache->memory_used -= entry->raw.len;
146140
kh_del(off, cache->entries, k);
147141
free_cache_object(entry);
148142
}
149-
}
143+
});
150144
}
151145

152146
static int cache_add(

src/revwalk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ void git_revwalk_reset(git_revwalk *walk)
702702

703703
assert(walk);
704704

705-
kh_foreach_value(walk->commits, commit, {
705+
git_oidmap_foreach_value(walk->commits, commit, {
706706
commit->seen = 0;
707707
commit->in_degree = 0;
708708
commit->topo_delay = 0;

src/transaction.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ static int update_target(git_refdb *db, transaction_node *node)
323323
int git_transaction_commit(git_transaction *tx)
324324
{
325325
transaction_node *node;
326-
git_strmap_iter pos;
327326
int error = 0;
328327

329328
assert(tx);
@@ -335,11 +334,7 @@ int git_transaction_commit(git_transaction *tx)
335334
return error;
336335
}
337336

338-
for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) {
339-
if (!git_strmap_has_data(tx->locks, pos))
340-
continue;
341-
342-
node = git_strmap_value_at(tx->locks, pos);
337+
git_strmap_foreach_value(tx->locks, node, {
343338
if (node->reflog) {
344339
if ((error = tx->db->backend->reflog_write(tx->db->backend, node->reflog)) < 0)
345340
return error;
@@ -349,7 +344,7 @@ int git_transaction_commit(git_transaction *tx)
349344
if ((error = update_target(tx->db, node)) < 0)
350345
return error;
351346
}
352-
}
347+
});
353348

354349
return 0;
355350
}
@@ -358,7 +353,6 @@ void git_transaction_free(git_transaction *tx)
358353
{
359354
transaction_node *node;
360355
git_pool pool;
361-
git_strmap_iter pos;
362356

363357
assert(tx);
364358

@@ -373,16 +367,12 @@ void git_transaction_free(git_transaction *tx)
373367
}
374368

375369
/* start by unlocking the ones we've left hanging, if any */
376-
for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) {
377-
if (!git_strmap_has_data(tx->locks, pos))
378-
continue;
379-
380-
node = git_strmap_value_at(tx->locks, pos);
370+
git_strmap_foreach_value(tx->locks, node, {
381371
if (node->committed)
382372
continue;
383373

384374
git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL);
385-
}
375+
});
386376

387377
git_refdb_free(tx->db);
388378
git_strmap_free(tx->locks);

0 commit comments

Comments
 (0)