]> git.proxmox.com Git - libgit2.git/commitdiff
khash: avoid using `kh_val`/`kh_value` directly
authorPatrick Steinhardt <ps@pks.im>
Wed, 25 Jan 2017 13:26:58 +0000 (14:26 +0100)
committerPatrick Steinhardt <ps@pks.im>
Fri, 17 Feb 2017 10:41:06 +0000 (11:41 +0100)
src/cache.c
src/indexer.c
src/odb_mempack.c
src/pack-objects.c
src/pack.c
src/revwalk.c
src/sortedcache.c
tests/core/oidmap.c

index ae42216c935d5d8367c4681fe1f9d63e64c0db1f..c5f576a808b8bcc3a77aa9a2489ad44186f9a9a5 100644 (file)
@@ -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 */
                }
index b5d5fd0d2479eef4571a9a3f66e72b29b2280335..303dd7cc7177ec69540315e0dc66fc9bf9278671 100644 (file)
@@ -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)
index b55ce7310e59dec85759b0a2565617176f928ec2..1b8987ef8726f28c6686a5febedd890944e0349f 100644 (file)
@@ -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;
index e463820e47265cd8839685b079b5edddf772f2cf..01286fa56407e24a03fe2ca1b7d914219d4b4c17 100644 (file)
@@ -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 */
index 43ef098013a8a2dce28a957e03e66416340377dd..4c2b9ebe09e631fda934f4e77c99103d447136d7 100644 (file)
@@ -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
index 75266650951e003249011da888ed7346a9832541..32a4ff906e4491479c6da8037d29635f8a7403ea 100644 (file)
@@ -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;
 }
index c5e338f75c5800c2d8b3c9bf7d048fa394de08f3..48e8b6c714679befd93e46278d22e8776194550b 100644 (file)
@@ -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)
index 2255e393688b80422b27e90f48e5561497e2e83a..61d75e9d114006369bc8194ed999fd48aa635271 100644 (file)
@@ -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);