Commit 852bc9f4 by Patrick Steinhardt

khash: remove intricate knowledge of khash types

Instead of using the `khiter_t`, `git_strmap_iter` and `khint_t` types,
simply use `size_t` instead. This decouples code from the khash stuff
and makes it possible to move the khash includes into the implementation
files.
parent 5bfb3b58
......@@ -33,7 +33,7 @@ GIT_INLINE(void) attr_cache_unlock(git_attr_cache *cache)
GIT_INLINE(git_attr_file_entry *) attr_cache_lookup_entry(
git_attr_cache *cache, const char *path)
{
khiter_t pos = git_strmap_lookup_index(cache->files, path);
size_t pos = git_strmap_lookup_index(cache->files, path);
if (git_strmap_valid_index(cache->files, pos))
return git_strmap_value_at(cache->files, pos);
......@@ -266,7 +266,7 @@ bool git_attr_cache__is_cached(
{
git_attr_cache *cache = git_repository_attr_cache(repo);
git_strmap *files;
khiter_t pos;
size_t pos;
git_attr_file_entry *entry;
if (!cache || !(files = cache->files))
......@@ -457,7 +457,7 @@ git_attr_rule *git_attr_cache__lookup_macro(
git_repository *repo, const char *name)
{
git_strmap *macros = git_repository_attr_cache(repo)->macros;
khiter_t pos;
size_t pos;
pos = git_strmap_lookup_index(macros, name);
......
......@@ -123,7 +123,7 @@ static void cache_evict_entries(git_cache *cache)
}
while (evict_count > 0) {
khiter_t pos = seed++ % git_oidmap_end(cache->map);
size_t pos = seed++ % git_oidmap_end(cache->map);
if (git_oidmap_has_data(cache->map, pos)) {
git_cached_obj *evict = git_oidmap_value_at(cache->map, pos);
......@@ -148,7 +148,7 @@ static bool cache_should_store(git_otype object_type, size_t object_size)
static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
{
khiter_t pos;
size_t pos;
git_cached_obj *entry = NULL;
if (!git_cache__enabled || git_rwlock_rdlock(&cache->lock) < 0)
......@@ -172,7 +172,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
static void *cache_store(git_cache *cache, git_cached_obj *entry)
{
khiter_t pos;
size_t pos;
git_cached_obj_incref(entry);
......
......@@ -131,9 +131,9 @@ void git_config_entries_free(git_config_entries *entries)
int git_config_entries_append(git_config_entries *entries, git_config_entry *entry)
{
git_strmap_iter pos;
config_entry_list *existing, *var;
int error = 0;
size_t pos;
var = git__calloc(1, sizeof(config_entry_list));
GITERR_CHECK_ALLOC(var);
......@@ -171,7 +171,7 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent
int config_entry_get(config_entry_list **out, git_config_entries *entries, const char *key)
{
khiter_t pos;
size_t pos;
pos = git_strmap_lookup_index(entries->map, key);
......
......@@ -36,7 +36,7 @@ struct commit_name {
static void *oidmap_value_bykey(git_oidmap *map, const git_oid *key)
{
khint_t pos = git_oidmap_lookup_index(map, key);
size_t pos = git_oidmap_lookup_index(map, key);
if (!git_oidmap_valid_index(map, pos))
return NULL;
......
......@@ -234,8 +234,7 @@ static int git_diff_driver_load(
int error = 0;
git_diff_driver_registry *reg;
git_diff_driver *drv = NULL;
size_t namelen;
khiter_t pos;
size_t namelen, pos;
git_config *cfg = NULL;
git_buf name = GIT_BUF_INIT;
git_config_entry *ce = NULL;
......
......@@ -29,7 +29,7 @@
#define INSERT_IN_MAP_EX(idx, map, e, err) do { \
if ((idx)->ignore_case) \
git_idxmap_icase_insert((khash_t(idxicase) *) (map), (e), (e), (err)); \
git_idxmap_icase_insert((git_idxmap_icase *) (map), (e), (e), (err)); \
else \
git_idxmap_insert((map), (e), (e), (err)); \
} while (0)
......@@ -38,14 +38,14 @@
#define LOOKUP_IN_MAP(p, idx, k) do { \
if ((idx)->ignore_case) \
(p) = git_idxmap_icase_lookup_index((khash_t(idxicase) *) index->entries_map, (k)); \
(p) = git_idxmap_icase_lookup_index((git_idxmap_icase *) index->entries_map, (k)); \
else \
(p) = git_idxmap_lookup_index(index->entries_map, (k)); \
} while (0)
#define DELETE_IN_MAP(idx, e) do { \
if ((idx)->ignore_case) \
git_idxmap_icase_delete((khash_t(idxicase) *) (idx)->entries_map, (e)); \
git_idxmap_icase_delete((git_idxmap_icase *) (idx)->entries_map, (e)); \
else \
git_idxmap_delete((idx)->entries_map, (e)); \
} while (0)
......@@ -851,8 +851,8 @@ const git_index_entry *git_index_get_byindex(
const git_index_entry *git_index_get_bypath(
git_index *index, const char *path, int stage)
{
khiter_t pos;
git_index_entry key = {{ 0 }};
size_t pos;
assert(index);
......@@ -1619,7 +1619,7 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
return 0;
git_vector_size_hint(&index->entries, source_entries->length);
git_idxmap_resize(index->entries_map, (khint_t)(source_entries->length * 1.3));
git_idxmap_resize(index->entries_map, (size_t)(source_entries->length * 1.3));
git_vector_foreach(source_entries, i, source_entry) {
git_index_entry *entry = NULL;
......@@ -2603,7 +2603,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
assert(!index->entries.length);
if (index->ignore_case)
git_idxmap_icase_resize((khash_t(idxicase) *) index->entries_map, header.entry_count);
git_idxmap_icase_resize((git_idxmap_icase *) index->entries_map, header.entry_count);
else
git_idxmap_resize(index->entries_map, header.entry_count);
......@@ -3124,7 +3124,7 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
goto cleanup;
if (index->ignore_case)
git_idxmap_icase_resize((khash_t(idxicase) *) entries_map, entries.length);
git_idxmap_icase_resize((git_idxmap_icase *) entries_map, entries.length);
else
git_idxmap_resize(entries_map, entries.length);
......@@ -3184,7 +3184,7 @@ static int git_index_read_iterator(
goto done;
if (index->ignore_case && new_length_hint)
git_idxmap_icase_resize((khash_t(idxicase) *) new_entries_map, new_length_hint);
git_idxmap_icase_resize((git_idxmap_icase *) new_entries_map, new_length_hint);
else if (new_length_hint)
git_idxmap_resize(new_entries_map, new_length_hint);
......
......@@ -402,7 +402,7 @@ out:
static int store_object(git_indexer *idx)
{
int i, error;
khiter_t k;
size_t k;
git_oid oid;
struct entry *entry;
git_off_t entry_size;
......@@ -483,7 +483,7 @@ GIT_INLINE(bool) has_entry(git_indexer *idx, git_oid *id)
static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_entry *pentry, git_off_t entry_start)
{
int i, error;
khiter_t k;
size_t k;
if (entry_start > UINT31_MAX) {
entry->offset = UINT32_MAX;
......@@ -1292,7 +1292,7 @@ on_error:
void git_indexer_free(git_indexer *idx)
{
khiter_t pos;
size_t pos;
if (idx == NULL)
return;
......
......@@ -1105,7 +1105,7 @@ static void deletes_by_oid_free(git_oidmap *map) {
}
static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid *id, size_t idx) {
khint_t pos;
size_t pos;
deletes_by_oid_queue *queue;
size_t *array_entry;
int error;
......@@ -1133,7 +1133,7 @@ static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid
}
static int deletes_by_oid_dequeue(size_t *idx, git_oidmap *map, const git_oid *id) {
khint_t pos;
size_t pos;
deletes_by_oid_queue *queue;
size_t *array_entry;
......
......@@ -51,7 +51,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
{
int error;
char *packname;
git_strmap_iter pos;
size_t pos;
struct git_pack_file *pack;
if ((error = git_packfile__name(&packname, path)) < 0)
......@@ -97,7 +97,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
void git_mwindow_put_pack(struct git_pack_file *pack)
{
int count;
git_strmap_iter pos;
size_t pos;
if (git_mutex_lock(&git__mwindow_mutex) < 0)
return;
......
......@@ -37,7 +37,7 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void
{
struct memory_packer_db *db = (struct memory_packer_db *)_backend;
struct memobject *obj = NULL;
khiter_t pos;
size_t pos;
size_t alloc_len;
int rval;
......@@ -80,7 +80,7 @@ static int impl__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb
{
struct memory_packer_db *db = (struct memory_packer_db *)backend;
struct memobject *obj = NULL;
khiter_t pos;
size_t pos;
pos = git_oidmap_lookup_index(db->objects, oid);
if (!git_oidmap_valid_index(db->objects, pos))
......@@ -101,7 +101,7 @@ static int impl__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *
{
struct memory_packer_db *db = (struct memory_packer_db *)backend;
struct memobject *obj = NULL;
khiter_t pos;
size_t pos;
pos = git_oidmap_lookup_index(db->objects, oid);
if (!git_oidmap_valid_index(db->objects, pos))
......
......@@ -197,8 +197,7 @@ unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n)
static void rehash(git_packbuilder *pb)
{
git_pobject *po;
khiter_t pos;
size_t i;
size_t pos, i;
int ret;
git_oidmap_clear(pb->object_ix);
......@@ -212,8 +211,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
const char *name)
{
git_pobject *po;
khiter_t pos;
size_t newsize;
size_t newsize, pos;
int ret;
assert(pb && oid);
......@@ -516,7 +514,7 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
{
git_packbuilder *pb = data;
git_pobject *po;
khiter_t pos;
size_t pos;
GIT_UNUSED(name);
......@@ -1542,7 +1540,7 @@ static int lookup_walk_object(struct walk_object **out, git_packbuilder *pb, con
static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id)
{
int error;
khiter_t pos;
size_t pos;
struct walk_object *obj;
pos = git_oidmap_lookup_index(pb->walk_objects, id);
......
......@@ -108,8 +108,8 @@ static int cache_init(git_pack_cache *cache)
static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
{
khiter_t k;
git_pack_cache_entry *entry = NULL;
size_t k;
if (git_mutex_lock(&cache->lock) < 0)
return NULL;
......@@ -148,7 +148,7 @@ static int cache_add(
{
git_pack_cache_entry *entry;
int error, exists = 0;
khiter_t k;
size_t k;
if (base->len > GIT_PACK_CACHE_SIZE_LIMIT)
return -1;
......@@ -954,8 +954,8 @@ git_off_t get_delta_base(
} else if (type == GIT_OBJ_REF_DELTA) {
/* If we have the cooperative cache, search in it first */
if (p->has_cache) {
khiter_t k;
git_oid oid;
size_t k;
git_oid_fromraw(&oid, base_info);
k = git_oidmap_lookup_index(p->idx_cache, &oid);
......
......@@ -21,7 +21,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
git_revwalk *walk, const git_oid *oid)
{
git_commit_list_node *commit;
khiter_t pos;
size_t pos;
int ret;
/* lookup and reserve space if not already present */
......
......@@ -270,8 +270,8 @@ int git_sortedcache_clear(git_sortedcache *sc, bool wlock)
/* find and/or insert item, returning pointer to item data */
int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key)
{
size_t pos;
int error = 0;
khiter_t pos;
void *item;
size_t keylen, itemlen;
char *item_key;
......@@ -320,7 +320,7 @@ done:
/* lookup item by key */
void *git_sortedcache_lookup(const git_sortedcache *sc, const char *key)
{
khiter_t pos = git_strmap_lookup_index(sc->map, key);
size_t pos = git_strmap_lookup_index(sc->map, key);
if (git_strmap_valid_index(sc->map, pos))
return git_strmap_value_at(sc->map, pos);
return NULL;
......@@ -371,7 +371,7 @@ int git_sortedcache_lookup_index(
int git_sortedcache_remove(git_sortedcache *sc, size_t pos)
{
char *item;
khiter_t mappos;
size_t mappos;
/* because of pool allocation, this can't actually remove the item,
* but we can remove it from the items vector and the hash table.
......
......@@ -115,7 +115,7 @@ size_t git_strmap_end(git_strmap *map)
int git_strmap_next(
void **data,
git_strmap_iter* iter,
size_t* iter,
git_strmap *map)
{
if (!map)
......
......@@ -62,7 +62,7 @@ size_t git_strmap_end(git_strmap *map);
int git_strmap_next(
void **data,
git_strmap_iter* iter,
size_t *iter,
git_strmap *map);
#endif
......@@ -267,7 +267,7 @@ int git_submodule_lookup(
}
if (repo->submodule_cache != NULL) {
khiter_t pos = git_strmap_lookup_index(repo->submodule_cache, name);
size_t pos = git_strmap_lookup_index(repo->submodule_cache, name);
if (git_strmap_valid_index(repo->submodule_cache, pos)) {
if (out) {
*out = git_strmap_value_at(repo->submodule_cache, pos);
......@@ -396,7 +396,7 @@ static void submodule_free_dup(void *sm)
static int submodule_get_or_create(git_submodule **out, git_repository *repo, git_strmap *map, const char *name)
{
int error = 0;
khiter_t pos;
size_t pos;
git_submodule *sm = NULL;
pos = git_strmap_lookup_index(map, name);
......@@ -439,7 +439,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf
goto done;
while (!(error = git_iterator_advance(&entry, i))) {
khiter_t pos = git_strmap_lookup_index(map, entry->path);
size_t pos = git_strmap_lookup_index(map, entry->path);
git_submodule *sm;
if (git_strmap_valid_index(map, pos)) {
......@@ -450,7 +450,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf
else
sm->flags |= GIT_SUBMODULE_STATUS__INDEX_NOT_SUBMODULE;
} else if (S_ISGITLINK(entry->mode)) {
khiter_t name_pos;
size_t name_pos;
const char *name;
name_pos = git_strmap_lookup_index(names, entry->path);
......@@ -491,7 +491,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg
goto done;
while (!(error = git_iterator_advance(&entry, i))) {
khiter_t pos = git_strmap_lookup_index(map, entry->path);
size_t pos = git_strmap_lookup_index(map, entry->path);
git_submodule *sm;
if (git_strmap_valid_index(map, pos)) {
......@@ -502,7 +502,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg
else
sm->flags |= GIT_SUBMODULE_STATUS__HEAD_NOT_SUBMODULE;
} else if (S_ISGITLINK(entry->mode)) {
khiter_t name_pos;
size_t name_pos;
const char *name;
name_pos = git_strmap_lookup_index(names, entry->path);
......@@ -1935,7 +1935,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
{
lfc_data *data = payload;
const char *namestart, *property;
git_strmap_iter pos;
size_t pos;
git_strmap *map = data->map;
git_buf name = GIT_BUF_INIT;
git_submodule *sm;
......
......@@ -133,8 +133,8 @@ cleanup:
static int find_locked(transaction_node **out, git_transaction *tx, const char *refname)
{
git_strmap_iter pos;
transaction_node *node;
size_t pos;
pos = git_strmap_lookup_index(tx->locks, refname);
if (!git_strmap_valid_index(tx->locks, pos)) {
......
......@@ -723,7 +723,7 @@ int git_treebuilder_insert(
{
git_tree_entry *entry;
int error;
git_strmap_iter pos;
size_t pos;
assert(bld && id && filename);
......@@ -758,7 +758,7 @@ int git_treebuilder_insert(
static git_tree_entry *treebuilder_get(git_treebuilder *bld, const char *filename)
{
git_tree_entry *entry = NULL;
git_strmap_iter pos;
size_t pos;
assert(bld && filename);
......
......@@ -28,7 +28,7 @@ void test_core_oidmap__basic(void)
cl_assert(map != NULL);
for (i = 0; i < NITEMS; ++i) {
khiter_t pos;
size_t pos;
int ret;
pos = git_oidmap_lookup_index(map, &items[i].oid);
......@@ -42,7 +42,7 @@ void test_core_oidmap__basic(void)
for (i = 0; i < NITEMS; ++i) {
khiter_t pos;
size_t pos;
pos = git_oidmap_lookup_index(map, &items[i].oid);
cl_assert(git_oidmap_valid_index(map, pos));
......@@ -82,7 +82,7 @@ void test_core_oidmap__hash_collision(void)
cl_assert(map != NULL);
for (i = 0; i < NITEMS; ++i) {
khiter_t pos;
size_t pos;
int ret;
pos = git_oidmap_lookup_index(map, &items[i].oid);
......@@ -96,7 +96,7 @@ void test_core_oidmap__hash_collision(void)
for (i = 0; i < NITEMS; ++i) {
khiter_t pos;
size_t pos;
pos = git_oidmap_lookup_index(map, &items[i].oid);
cl_assert(git_oidmap_valid_index(map, pos));
......
......@@ -60,7 +60,7 @@ void test_core_strmap__1(void)
void test_core_strmap__2(void)
{
khiter_t pos;
size_t pos;
int i;
char *str;
......
......@@ -11,7 +11,7 @@ void test_pack_sharing__open_two_repos(void)
git_repository *repo1, *repo2;
git_object *obj1, *obj2;
git_oid id;
git_strmap_iter pos;
size_t pos;
void *data;
int error;
......
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