Skip to content

Commit

Permalink
Merge branch 'bw/oidmap-autoinit'
Browse files Browse the repository at this point in the history
Code clean-up.

* bw/oidmap-autoinit:
  oidmap: ensure map is initialized
  • Loading branch information
gitster committed Jan 23, 2018
2 parents 5550449 + e2a5a02 commit d470b7a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions oidmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,30 @@ void oidmap_free(struct oidmap *map, int free_entries)

void *oidmap_get(const struct oidmap *map, const struct object_id *key)
{
if (!map->map.cmpfn)
return NULL;

return hashmap_get_from_hash(&map->map, hash(key), key);
}

void *oidmap_remove(struct oidmap *map, const struct object_id *key)
{
struct hashmap_entry entry;

if (!map->map.cmpfn)
oidmap_init(map, 0);

hashmap_entry_init(&entry, hash(key));
return hashmap_remove(&map->map, &entry, key);
}

void *oidmap_put(struct oidmap *map, void *entry)
{
struct oidmap_entry *to_put = entry;

if (!map->map.cmpfn)
oidmap_init(map, 0);

hashmap_entry_init(&to_put->internal_entry, hash(&to_put->oid));
return hashmap_put(&map->map, to_put);
}

0 comments on commit d470b7a

Please sign in to comment.