Skip to content

Commit 036daa5

Browse files
committed
khash: use git_map_exists where applicable
1 parent 9694d9b commit 036daa5

File tree

5 files changed

+6
-12
lines changed

5 files changed

+6
-12
lines changed

src/indexer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,7 @@ static int store_object(git_indexer *idx)
333333

334334
GIT_INLINE(bool) has_entry(git_indexer *idx, git_oid *id)
335335
{
336-
khiter_t k;
337-
k = kh_get(oid, idx->pack->idx_cache, id);
338-
return (k != kh_end(idx->pack->idx_cache));
336+
return git_oidmap_exists(idx->pack->idx_cache, id);
339337
}
340338

341339
static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_entry *pentry, git_off_t entry_start)

src/odb_mempack.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,8 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void
7272
static int impl__exists(git_odb_backend *backend, const git_oid *oid)
7373
{
7474
struct memory_packer_db *db = (struct memory_packer_db *)backend;
75-
khiter_t pos;
76-
77-
pos = kh_get(oid, db->objects, oid);
78-
if (pos != kh_end(db->objects))
79-
return 1;
8075

81-
return 0;
76+
return git_oidmap_exists(db->objects, oid);
8277
}
8378

8479
static int impl__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)

src/oidmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
3636
#define git_oidmap_lookup_index(h, k) kh_get(oid, h, k)
3737
#define git_oidmap_valid_index(h, idx) (idx != kh_end(h))
3838

39+
#define git_oidmap_exists(h, k) (kh_get(oid, h, k) != kh_end(h))
40+
3941
#define git_oidmap_value_at(h, idx) kh_val(h, idx)
4042

4143
#define git_oidmap_insert(h, key, val, rval) do { \

src/pack-objects.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
216216

217217
/* If the object already exists in the hash table, then we don't
218218
* have any work to do */
219-
pos = kh_get(oid, pb->object_ix, oid);
220-
if (pos != kh_end(pb->object_ix))
219+
if (git_oidmap_exists(pb->object_ix, oid))
221220
return 0;
222221

223222
if (pb->nr_objects >= pb->nr_alloc) {

src/pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static int cache_add(
164164
return -1;
165165
}
166166
/* Add it to the cache if nobody else has */
167-
exists = kh_get(off, cache->entries, offset) != kh_end(cache->entries);
167+
exists = git_offmap_exists(cache->entries, offset);
168168
if (!exists) {
169169
while (cache->memory_used + base->len > cache->memory_limit)
170170
free_lowest_entry(cache);

0 commit comments

Comments
 (0)