Commit 9694d9ba by Patrick Steinhardt

khash: avoid using `kh_foreach`/`kh_foreach_value` directly

parent 63e914cb
...@@ -53,7 +53,7 @@ void git_cache_dump_stats(git_cache *cache) ...@@ -53,7 +53,7 @@ void git_cache_dump_stats(git_cache *cache)
printf("Cache %p: %"PRIuZ" items cached, %"PRIdZ" bytes\n", printf("Cache %p: %"PRIuZ" items cached, %"PRIdZ" bytes\n",
cache, git_cache_size(cache), cache->used_memory); cache, git_cache_size(cache), cache->used_memory);
kh_foreach_value(cache->map, object, { git_oidmap_foreach_value(cache->map, object, {
char oid_str[9]; char oid_str[9];
printf(" %s%c %s (%"PRIuZ")\n", printf(" %s%c %s (%"PRIuZ")\n",
git_object_type2string(object->type), git_object_type2string(object->type),
...@@ -84,7 +84,7 @@ static void clear_cache(git_cache *cache) ...@@ -84,7 +84,7 @@ static void clear_cache(git_cache *cache)
if (git_cache_size(cache) == 0) if (git_cache_size(cache) == 0)
return; return;
kh_foreach_value(cache->map, evict, { git_oidmap_foreach_value(cache->map, evict, {
git_cached_obj_decref(evict); git_cached_obj_decref(evict);
}); });
......
...@@ -1106,8 +1106,9 @@ void git_indexer_free(git_indexer *idx) ...@@ -1106,8 +1106,9 @@ void git_indexer_free(git_indexer *idx)
if (idx->pack->idx_cache) { if (idx->pack->idx_cache) {
struct git_pack_entry *pentry; struct git_pack_entry *pentry;
kh_foreach_value( git_oidmap_foreach_value(idx->pack->idx_cache, pentry, {
idx->pack->idx_cache, pentry, { git__free(pentry); }); git__free(pentry);
});
git_oidmap_free(idx->pack->idx_cache); git_oidmap_free(idx->pack->idx_cache);
} }
......
...@@ -149,7 +149,7 @@ void git_mempack_reset(git_odb_backend *_backend) ...@@ -149,7 +149,7 @@ void git_mempack_reset(git_odb_backend *_backend)
struct memory_packer_db *db = (struct memory_packer_db *)_backend; struct memory_packer_db *db = (struct memory_packer_db *)_backend;
struct memobject *object = NULL; struct memobject *object = NULL;
kh_foreach_value(db->objects, object, { git_oidmap_foreach_value(db->objects, object, {
git__free(object); git__free(object);
}); });
......
...@@ -78,13 +78,12 @@ static void free_cache_object(void *o) ...@@ -78,13 +78,12 @@ static void free_cache_object(void *o)
static void cache_free(git_pack_cache *cache) static void cache_free(git_pack_cache *cache)
{ {
khiter_t k; git_pack_cache_entry *entry;
if (cache->entries) { if (cache->entries) {
for (k = kh_begin(cache->entries); k != kh_end(cache->entries); k++) { git_offmap_foreach_value(cache->entries, entry, {
if (kh_exist(cache->entries, k)) free_cache_object(entry);
free_cache_object(kh_value(cache->entries, k)); });
}
git_offmap_free(cache->entries); git_offmap_free(cache->entries);
cache->entries = NULL; cache->entries = NULL;
...@@ -135,18 +134,13 @@ static void free_lowest_entry(git_pack_cache *cache) ...@@ -135,18 +134,13 @@ static void free_lowest_entry(git_pack_cache *cache)
git_pack_cache_entry *entry; git_pack_cache_entry *entry;
khiter_t k; khiter_t k;
for (k = kh_begin(cache->entries); k != kh_end(cache->entries); k++) { git_offmap_foreach(cache->entries, k, entry, {
if (!kh_exist(cache->entries, k))
continue;
entry = kh_value(cache->entries, k);
if (entry && entry->refcount.val == 0) { if (entry && entry->refcount.val == 0) {
cache->memory_used -= entry->raw.len; cache->memory_used -= entry->raw.len;
kh_del(off, cache->entries, k); kh_del(off, cache->entries, k);
free_cache_object(entry); free_cache_object(entry);
} }
} });
} }
static int cache_add( static int cache_add(
......
...@@ -702,7 +702,7 @@ void git_revwalk_reset(git_revwalk *walk) ...@@ -702,7 +702,7 @@ void git_revwalk_reset(git_revwalk *walk)
assert(walk); assert(walk);
kh_foreach_value(walk->commits, commit, { git_oidmap_foreach_value(walk->commits, commit, {
commit->seen = 0; commit->seen = 0;
commit->in_degree = 0; commit->in_degree = 0;
commit->topo_delay = 0; commit->topo_delay = 0;
......
...@@ -323,7 +323,6 @@ static int update_target(git_refdb *db, transaction_node *node) ...@@ -323,7 +323,6 @@ static int update_target(git_refdb *db, transaction_node *node)
int git_transaction_commit(git_transaction *tx) int git_transaction_commit(git_transaction *tx)
{ {
transaction_node *node; transaction_node *node;
git_strmap_iter pos;
int error = 0; int error = 0;
assert(tx); assert(tx);
...@@ -335,11 +334,7 @@ int git_transaction_commit(git_transaction *tx) ...@@ -335,11 +334,7 @@ int git_transaction_commit(git_transaction *tx)
return error; return error;
} }
for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) { git_strmap_foreach_value(tx->locks, node, {
if (!git_strmap_has_data(tx->locks, pos))
continue;
node = git_strmap_value_at(tx->locks, pos);
if (node->reflog) { if (node->reflog) {
if ((error = tx->db->backend->reflog_write(tx->db->backend, node->reflog)) < 0) if ((error = tx->db->backend->reflog_write(tx->db->backend, node->reflog)) < 0)
return error; return error;
...@@ -349,7 +344,7 @@ int git_transaction_commit(git_transaction *tx) ...@@ -349,7 +344,7 @@ int git_transaction_commit(git_transaction *tx)
if ((error = update_target(tx->db, node)) < 0) if ((error = update_target(tx->db, node)) < 0)
return error; return error;
} }
} });
return 0; return 0;
} }
...@@ -358,7 +353,6 @@ void git_transaction_free(git_transaction *tx) ...@@ -358,7 +353,6 @@ void git_transaction_free(git_transaction *tx)
{ {
transaction_node *node; transaction_node *node;
git_pool pool; git_pool pool;
git_strmap_iter pos;
assert(tx); assert(tx);
...@@ -373,16 +367,12 @@ void git_transaction_free(git_transaction *tx) ...@@ -373,16 +367,12 @@ void git_transaction_free(git_transaction *tx)
} }
/* start by unlocking the ones we've left hanging, if any */ /* start by unlocking the ones we've left hanging, if any */
for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) { git_strmap_foreach_value(tx->locks, node, {
if (!git_strmap_has_data(tx->locks, pos))
continue;
node = git_strmap_value_at(tx->locks, pos);
if (node->committed) if (node->committed)
continue; continue;
git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL); git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL);
} });
git_refdb_free(tx->db); git_refdb_free(tx->db);
git_strmap_free(tx->locks); git_strmap_free(tx->locks);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment